visible and invisible logic

joe789

Registered User.
Local time
Today, 16:54
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I got a form that has quite a few areas where I am trying to make certain fields visible or invisible contingent/based upon the user selection in other fields. For instance, if a user selects a specific item from a combo box, the relevant and associated fields with that answer would be shown and the non-relevant fields would be hidden.

Here is the interesting thing: I am able to successfully use the code below and it successfully hides or shows fields based on whatever is updated in the combo box:

Private Sub growingup_afterupdate()

If Me.GrowingUp = "Two Parent Household" Then
Me.Check199.Visible = True
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
ElseIf Me.GrowingUp = "Single Parent Household" Then
Me.Check199.Visible = False
Me.Combo203.Visible = True
Me.Text210.Visible = False
Me.Check204.Visible = True
Me.Label454.Visible = True
ElseIf Me.GrowingUp = "Grandparent" Then
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
ElseIf Me.GrowingUp = "Other" Then
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = True
Me.Check204.Visible = False
Me.Label454.Visible = True
Else
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
End If

End Sub

However, if I use this same code on the form load, it will not work!

Private Sub Form_Load()

If Me.GrowingUp = "Two Parent Household" Then
Me.Check199.Visible = True
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
ElseIf Me.GrowingUp = "Single Parent Household" Then
Me.Check199.Visible = False
Me.Combo203.Visible = True
Me.Text210.Visible = False
Me.Check204.Visible = True
Me.Label454.Visible = True
ElseIf Me.GrowingUp = "Grandparent" Then
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
ElseIf Me.GrowingUp = "Other" Then
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = True
Me.Check204.Visible = False
Me.Label454.Visible = True
Else
Me.Check199.Visible = False
Me.Combo203.Visible = False
Me.Text210.Visible = False
Me.Check204.Visible = False
Me.Label454.Visible = False
End If

End Sub


I am not sure why the code works perfectly via the afterupdate but the exact same code fails to work via the form_Load ... the reason I need both to work is because there is a browse records and add new record feature in the form and therefore when the form is first opened it should show/hide whatever it needs to based on the combo box selection -AND- should show/hide whatever is needed based on if a user updates the combo box (the later functioning works fine)?

Any ideas would be greatly appreciated ... thanks,

Joe
 
One easy way to do is.. Make all checkboxes invisible in design mode.. Then based on the option make them visible avoids too many confusing TRUE/FALSE..

Which makes me wonder, are these options unbound? If the form is bound to the table I do not think you need to make them visible/invisible on every form load..
 
Try the current event rather than the load event. It's the one you want anyway, to catch the changing of records.
 
Some unsolicited advice:
Change the control names to something meaningful. You probably already don't know what Label454 is. Warning - if you have event code associated with these controls it will be orphaned so change them one at a time so you can move the code as necessary and compile so you can fix the compile errors. This is quite a pain at this point but if you use good hygiene going forward, you will give the controls meaningful names from the outset and not ever have to do this again. Common practice is to use the field name prefixed with txt, cbo, cmb, chk, etc. so you can easily match fields to controls and the lbls are similarly named.
 

Users who are viewing this thread

Back
Top Bottom