Disable button if a combo box is blank

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

Guest

Hi,

I have 2 combo boxes, both based on queries, the second one, filter results
depending on what was selected from the first combo box.
When the form is opened it tests to see if the second box is null here is my
code -

Private Sub Form_Open(Cancel As Integer)
If IsNull(Me!cmbprojectreference) Then
Me.cmdaddimage.Visible = False
Else
Me.cmdaddimage.Visible = True
End If
End Sub

This works fine, however if I have selected values from each combo box(and
the subform displays results in the subform)and then decide to change the
value in the 1st combo box, I want the button to be disabled again until a
value is chosen from the 2nd combo box.

Any ideas

TIA

Rich
 
Rich,

You need to put the same code in both combos' On Change event, as well
as in the form's On Current event. The latter fires as you move between
records; once this is used, the On Open one is redundant, as the Current
fires when the form opens anyway.

By the way, your If structure can be replaced by:

Me.cmdaddimage.Visible = Not IsNull(Me!cmbprojectreference)

HTH,
Nikos
 
Back
Top