Hide Labels depending on checkbox value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ezappsrUS
    New Member
    • Jun 2023
    • 3

    Hide Labels depending on checkbox value

    Hi,
    I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox [active] being checked or not. Below is the code. Visibility is not adhering to the record [active] checkbox value. Screenshot also below. Any ideas?
    Code:
    Private Sub Form_Current()
        Dim db As DAO.Database
        Set db = CurrentDb
    
        lblinactive.Visible = False
        lblactive.Visible = False
    
    '+++++++++++++++++++++++
    
        If Me.active.Value = 0 Then
            lblinactive.Visible = True
            lblactive.Visible = False
        Else
            lblinactive.Visible = False
            lblactive.Visible = True
        End If
    End Sub
    Last edited by NeoPa; Jun 11 '23, 07:03 PM. Reason: Added [CODE] tags and formatted code to be legible.
  • ezappsrUS
    New Member
    • Jun 2023
    • 3

    #2
    Additionally, if I change to single form then code works when paging down. Form is needed to show many records (continuous) for users to view and choose. Thanks again.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Hi ezappsrUS.

      Welcome to Bytes.com :-)

      Please read and understand Why Values in Unbound Form Controls do not Persist in order to understand why it might work for Single Forms but not Continuous ones.

      You may want to consider Conditional Formatting to manage showing each record correctly. That wouldn't require code to update every time you move between records.

      BTW, your routine can be considerably simplified to :
      Code:
      Private Sub Form_Current()
          Me.lblActive.Visible = Me.Active
          Me.lblInactive.Visible = (Not Me.Active)
      End Sub

      Comment

      • ezappsrUS
        New Member
        • Jun 2023
        • 3

        #4
        Thanks for the tips. Question is solved.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Very pleased to hear it :-)

          Always nice when an OP (Opening Poster / Creator of Thread) replies & confirms their question is resolved.

          Comment

          Working...