Making Fields Invisible After Going to the Next Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have a field where if a certain field is selected from the drop down list
then certain fields become visible. How do you make these invisible when
moving to a new record
 
Use the form's Current event to toggle the visibility off:

Private Sub Form_Current()

Me.txtField1.Visible = False
Me.txtField2.Visible = False

End Sub
 
PhilipBenno said:
Hello

I have a field where if a certain field is selected from the drop down list
then certain fields become visible. How do you make these invisible when
moving to a new record

You want to use the Form_Current() event to set the visibility of your
controls. This fires each time you go to a new record.

What I'd recommend doing is creating a standalone function which changes
the visibility based on the value of the combobox. That way you can call
the same function in both the control's after update event, and the form
current event.

Private Sub SetupForm()
If cboMyComboBox = "SomeValue" Then
txtMyControl1.Visible = False
txtMyControl2.Visible = False
txtMyControl3.Visible = True
Else
txtMyControl1.Visible = True
txtMyControl2.Visible = True
txtMyControl3.Visible = False
End If
End Sub
 
I use a slight variation of the function that Duncan provided. Rather than
use an IF statement and have to provide the coding for both the IF and the
Else, I use:

Function ShowHideCtrls(bolStatus as Boolean)
Me.txtMyControl1.Visible = varStatus
Me.txtMyControl2.Visible = varStatus
Me.txtMyControl3.Visible = varStatus
Me.cmdMyButton1.Visible = Not varStatus
End Function

Then to hide or show the controls simply call the function as follows:

ShowHideCtrls(true) - To make controls visible
or
ShowHideCtrls(false) - To make controls not visible

Please note that the last item that i have in the function is a control that
I want to be hidden when all the others are visible.
 
Back
Top