Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set 0 to all controls of a form (Access 2000)

    in the OnOpen event of my form i have put the following code


    Dim ctl As Control
    For Each ctl In Me.Controls
    ctl.Value = 0
    Next

    I get however the error You can;t assign a vlue to this object.How can i assign
    a value of 0 to all object in the OnOpen event? If i enumerate the controls and assign the value 0 to them then it is ok, but not otherwise.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set 0 to all controls of a form (Access 2000)

    You have to check the control to see what kind it is. You can't assign a value to controls like labels, command buttons, etc. Try something like this:

    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acCheckBox
    ctl.Value = 0
    End Select
    Next ctl
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set 0 to all controls of a form (Access 2000)

    Thank you !!!

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Set 0 to all controls of a form (Access 2000)

    Of course Charlotte's tip fixed your code problem, but couldn't you have avoided it altogether merely by setting the default value for all your controls to 0?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •