Results 1 to 5 of 5
  1. #1
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182

    Hiding Fields Based on Checkbox

    I am having issues hiding a field. Basically, I have two fields. One is a CheckBox. The other is a Textfield.

    IF the CheckBox is Checked, then I want to "show" the Textfield. If it is not checked, then I want to hide the textfield. I do this by setting the Textfield property to visible=no. And I have the following VBA code.

    Private Sub CheckBox_AfterUpdate()


    Dim selCheckBox As Boolean
    selCheckBox = Me.[IsInDDS]
    Select Case selCheckBox
    Case "True"
    Me.[TextField].Visible = True
    Case "False"
    Me.[TextField].Visible = False
    End Select
    End Sub

    This works as I want.

    But everytime I load the form, I want "TextField" to be displayed if there is a value in it (or if CheckBox is checked yes).
    Last edited by zashaikh; 12-31-2017 at 08:08 PM.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Have you tried your code in the form's OnCurrent event as well.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    As suggested by B Fitz, you can do it this way to avoid repeating the code:

    Code:
    Private Sub Form_Current()
        Call CheckBox_AfterUpdate
    End Sub

  4. #4
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Thank you. I believe it is working now. Basically, if CheckBox is checked, it will show the textfield. If unchecked, it will not.

    THanks!

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    You really only need one line of code in Sub CheckBox_AfterUpdate()
    Code:
    Private Sub CheckBox_AfterUpdate()
       Me.[TextField].Visible = Me.[IsInCIS]
    End Sub
    where
    [TextField] is the text box control name and
    [IsInCIS] is the checkbox control name


    just sayin.......

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

Similar Threads

  1. Hide/Show fields at Form based on checkbox
    By cap.zadi in forum Forms
    Replies: 8
    Last Post: 04-22-2016, 05:08 AM
  2. Report Fields Visible Based on Checkbox
    By ghillie30 in forum Access
    Replies: 2
    Last Post: 09-21-2011, 09:04 AM
  3. Hiding checkbox on report
    By bluezidane in forum Reports
    Replies: 2
    Last Post: 06-29-2011, 12:46 PM
  4. Hiding fields in a subform
    By degras in forum Forms
    Replies: 7
    Last Post: 01-18-2011, 10:55 AM
  5. Replies: 1
    Last Post: 10-26-2007, 07:29 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