Results 1 to 4 of 4
  1. #1
    lisa071 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Location
    Virignia
    Posts
    2

    AfterUpdate Event Based on Checkbox

    Hi,
    I am trying to hide a certain field based on if a checkbox is checked or not. If the box is checked, the field should be hidden. If the box is not checked, the field should be visible. I have done this before and can't figure out what I am doing wrong now. Here is the code:

    Private Sub bxCheck_AfterUpdate()
    If bxCheck= "2" Then
    Field.Visible = False
    Else
    Field.Visible = True
    End If


    End Sub

    Please help! I want the field to appear and reappear based on when the box is checked and unchecked.

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Field.visible = boxcheck.value

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is the "2"?? You do know there is a difference between a number 2 (no quotes) and a "text" number "2" (with quotes).

    That is not the problem here. A check box is either TRUE or FALSE. In Access, FALSE = 0 and TRUE = -1. Actually TRUE = Not FALSE (ie anything other than 0 )

    So your code should be:
    Code:
    Private Sub bxCheck_AfterUpdate()
        If bxCheck = True Then    
            Field.Visible = False
        Else
            Field.Visible = True
        End If
    End Sub
    or
    Code:
    Private Sub bxCheck_AfterUpdate()
        If bxCheck Then
            Field.Visible = False
        Else
            Field.Visible = True
        End If
    End Sub
    or
    Code:
    Private Sub bxCheck_AfterUpdate()
            Field.Visible = Not (Me.bxCheck)
    End Sub

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ssanfu View Post

    What is the "2"??
    I wondered about this, too, and have to ask: Is this an independent Checkbox, or is it one of a series of Checkboxes in an Option Group? I ask because the Controls in an Option Group are not referenced individually...they are referred to by their position in the Group and the name of the Option Group, which Access calls a 'Frame.' If the Frame is named Frame10 and you want to know if the second Checkbox in the Group has been ticked, you'd use something like

    If Me.Frame10 = 2 Then

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 4
    Last Post: 02-27-2014, 03:39 PM
  2. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  3. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM
  4. AfterUpdate event code error?
    By agripa86 in forum Programming
    Replies: 3
    Last Post: 08-12-2011, 09:12 AM
  5. how to created afterupdate event
    By Brigitt in forum Forms
    Replies: 2
    Last Post: 02-15-2011, 03:23 AM

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