Results 1 to 5 of 5
  1. #1
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273

    Checkbox not working right

    Here's a strange little thing that's got me stumped...



    My form has a label whose Visible property is set to No. The form On Open property makes the label visible. On the On Click property of a checkbox on the form is the following code...

    If Me.chkPreInsp = Yes Then
    Me.lblStud.Visible = False
    Else:
    Me.lblStud.Visible = True
    End If

    When I check the box, the label stays visible. When I uncheck it, the label disappears. I changed the If statement from Yes to No, with the exact same effect. I also tried "Yes", "YES", "No", "NO", 0, 1, True and False, but the label only disappears when the box is unchecked, which is the opposite of what I want. This has got to be something small that will make me feel stupid, but I'm prepared for that!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    An If Then Else is not necessary. This works for me:

    Me.lblStud.Visible = Me.chkPreInsp = True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    AFAIK both Yes and True are constants in VBA. They both equal -1.

    If you place quotes around True or False then, VBA will interpret the literal text, not the constant.

    Having said that, I always use -1 for Yes and 0 for No in VBA. I use True and False in SQL.

    Code:
    If Me.chkPreInsp = True Then
    Me.lblStud.Visible = 0
    Else
    Me.lblStud.Visible = -1
    End If
    Notice that Else is not followed with a colon in the above example. You would use a colon to indicate you are going to continue your code on the same line.
    If Me.chkPreInsp = True Then Me.lblStud.Visible = 0 Else: Me.lblStud.Visible = -1

  4. #4
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    OK June, that goes against everything I thought I knew...2 equal signs in the same statement? But it works! Thanks for the help.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    As I understand it, the first equal sign defines the left and right sides of expression. Do this test in the VBA immediate window:

    ?(1 + 2)=(1 + 2)

    ?True = (1 + 2 = 3)

    ?True = True = False
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Yes or No Checkbox Help
    By bronson_mech in forum Queries
    Replies: 4
    Last Post: 11-30-2013, 05:33 PM
  2. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  3. Checkbox not working
    By terryvanduzee in forum Programming
    Replies: 4
    Last Post: 10-23-2009, 10:36 AM
  4. Checkbox
    By Rbtsmith in forum Access
    Replies: 2
    Last Post: 02-17-2009, 04:19 PM
  5. Replies: 0
    Last Post: 01-06-2009, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums