display form fields based on data entry

Objective: Create automated MS Access 2007 form that adjusts based on data entry.
We are trying to create a data entry form to store data and print reports on our clients. Not all people are married or have children, thus we want to form to adapt to each individual case.

Example Form:

Two fields to start with: Client_Name_Field Is_Married_Checkbox
If married, then display new field Spouse Name field and Children_checkbox
If children, then display field Child Name field and [additional_children_checkbox1
If additional children, display Child2 Name Field hide additional_children_checkbox1 and display additional_children_checkbox2
mobdogAsked:
Who is Participating?
 
SeanStricklandCommented:
This would work.  To elaborate on cwood's response... you would use this by setting the AfterUpdate() event (see field properties) so the code behind the form looks like this:

Private Sub Is_Married_Checkbox_AfterUpdate()
If Is_Married_Checkbox = True Then
    SpouseName.Visible = True
    Children_checkbox.Visible = True
    Me.Repaint
    DoEvents
Else
    SpouseName.Visible = False
    Children_checkbox.Visible = False
    Me.Repaint
    DoEvents
End If
End Sub

This will tell your form to run that code when the Is_Married_Checkbox is updated/changed.  The code says that if the box is true... set the spouse name and children checkbox to visible.  You should have the default VISIBLE properties on those two fields set to NO.
0
 
Chuck WoodCommented:
Set the Visible property of the fields you don't want displayed to No.
As the fields are needed, set their Visible property to Yes (see snippet).

If Is_Married_Checkbox = True Then
    SpouseName.Visible = True
    Children_checkbox.Visible = True
    Me.Repaint
    DoEvents
End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.