Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting a check box initial value in VBA code (Access 2003 / SP1)

    I am finding it impossible in VBA code to set an initial value for an Access forms check box, that is, how the option box is to appear (checked or unchecked) when its parent form is Opened. My check box, which is not part of any option group, is otherwise working fine: As it is physically clicked, it is correctly passing True or False to its Me!CheckBox_Click event procedure.

    Since I don't know how the box is to appear until its parent form is to be opened, I cannot pre-fill its Default Value property at design time; I must do it in code. I initialize all controls (all unbound) in the forms Form_Open event procedure.

    I've tried setting Me!CheckBox.DefaultValue to True, to "True", and even to "=True".
    I've also tried setting Me!CheckBox.Value to True, to "True", and again even to "=True".

    In all cases my code is ignored, and the check box is shown simply as grayed out. This all seems so simple; I'm following what the Help system is telling me to do. (I know, don't get you started on that.) And I am having no trouble setting starting values to other kinds of controls (option groups, etc.) in that same Form_Load procedure.

    Can someone please tell me how to do this?

    Thank you,

    John

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting a check box initial value in VBA code (Access 2003 / SP1)

    Instead of the On Open event, try the On Load event of the form.
    Francois

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting a check box initial value in VBA code

    As you suggested I moved Me!CheckBox.DefaultValue = True to the Form_Load event. It worked beautifully. Who would have known?

    Thank you for your help,

    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting a check box initial value in VBA code

    On Open occurs early, when the form is opened and before the first record is displayed. On Load occurs later, when the records are being displayed.

  5. #5
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting a check box initial value in VBA code

    Thanks again guys. Every bit of information helps.

    John

Posting Permissions

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