
Originally Posted by
Kirsti
Hi,
I have a form with a number of fields on it. When the form is first created, a few of these fields are 'required' in the table definition. However, users will come back later & add further information into the form. I need to set a lot of rules around the fields to force the users to enter all required information. e.g. they can't enter 'offer 2' information until all 'offer 1' information has been entered.
With some help from this forum last week, I got it working by setting visible to False on the Form_Current procedure. However, the issue I had is that if a user entered data, went away and came back to the form, the fields they had filled out are not visible.
I am new to VBA and have been trying to enter the following code:
Private Sub Form_Current()
If Field_1 Is Null Then
Field_1.Visible = False
Else: Field_1.Visible = True
If Field_2 Is Null Then
Field_2.Visible = False
Else: Field_2.Visible = True
End If
End Sub
But it's not working. Any help would be really appreciated!
Just to get terminology straight, forms have controls, controls are bound to fields. If you use the wizard to create a form with controls, Access names the control with the same name of the bound field. I would suggest renaming the controls slightly to differentiate the control names from the field names.
There were several problems with your code. Try this:
Code:
Private Sub Form_Current()
If IsNull(Me.Field_1) Then
Me.Field_1.Visible = False
Else
Me.Field_1.Visible = True
End If
If IsNull(Me.Field_2) Then
Me.Field_2.Visible = False
Else
Me.Field_2.Visible = True
End If
End Sub