BaldyWeb

How Can I Make a Control Visible Based on the Value of Another?

Sometimes you want to control the visibility (or other property) of one control to be based on the value in another.  This is the type of code you would use:
 
Code:
  
    If Me.ControlName = "Whatever" Then
        Me.OtherControlName.Visible = True
    Else
        Me.OtherControlName.Visible = False
    End If

Depending on your situation, you might also want to clear the contents of the second control if you're making it invisible.  You would put that code in the After Update event of the control you're testing, so that when you changed the value it would execute the code.  You might also want the code in the Current event, which would fire when you change records.

Similarly, to set a value in one control when another is changed (setting back is optional).  In this case the first control is a check box and the second is a date:
 
Code:
  
    If Me.CheckboxName = True Then
        Me.OtherControlName = Date()
    Else
        Me.OtherControlName = Null
    End If

Home