Keeping a combo box hidden until an option is selected in another combo box

michael.young

New member
Local time
Today, 14:34
Joined
Feb 28, 2008
Messages
4
I have a form with several combo boxes ('Area' 'Area2' 'Area 3'). Is it possible to keep the 'Area2' box hidden until the user selects an option from 'Area' and in turn keep 'Area3' hidden until the user selects an option from 'Area2' ?

Cheers!
 
Something like:

If Me.cmb1(0) = Null Then
Me.cmb2.visible = False
End If
 
thanks for the response, whereabouts do I need to put that code, in the AfterUpdate in event procedure?
 
Hmmm ya try it :)

I was just thinking off the top of my head, I've never done it before.
 
thanks for the response, whereabouts do I need to put that code, in the AfterUpdate in event procedure?

Yes, in the first combo's After Update event and also the form's On Current event so when you move from record to record it will show appropriately.
 
You probably also need to take into account the possibility that the user may change their mind and delete the selection from one of the combobxes, in which case you'd want to reset visibility of the dependent comboxes and remove the values entered in them. I think I've covered allthe permutations here.

Code:
Private Sub Area_AfterUpdate()
 If Not IsNull(Me.Area) Then
  Area2.Visible = True
 Else
  Area2.Visible = False
  Me.Area2 = Null
  Area3.Visible = False
  Me.Area3 = Null
 End If
End Sub
Code:
Private Sub Area2_AfterUpdate()
If Not IsNull(Me.Area2) Then
  Area3.Visible = True
 Else
  Area3.Visible = False
  Me.Area3 = Null
 End If
End Sub
Code:
Private Sub Form_Current()
 If Not IsNull(Me.Area) Then
  Area2.Visible = True
 Else
  Area2.Visible = False
  Area3.Visible = False
 End If
If Not IsNull(Me.Area2) Then
  Area3.Visible = True
 Else
  Area3.Visible = False
 End If
End Sub
 
Can you do the same thing with a sub form? Like hide a sub form until someone selects something from the combo box. I tried it as described above and it doesn't work. Also tried me.subform.enable = false
 
Just added that code in and it all appears to be working as required, cheers :)
 
Glad you got it working, Michael!

**********************

Couple of things, mnevitt:

me.subform.enable = false

should be

me.subform.enabled = false

and to use subform in the above, subform needs to be the name of the subform control, not the name of the form being used as a subform.
 
missingliq -
yes, minor typos. and of course the subform is named something totally different. was using that simply to try and get my idea across. like i mentioned i tried both options (.visible and .enabled) independently without what i thought the correct result should be. when .visible was false it was still there and when .enabled was false it wasn't "greyed" out and unaccessible.
 

Users who are viewing this thread

Back
Top Bottom