Disable button if a combo box is blank

R

Richard Smith

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
 
N

Nikos Yannacopoulos

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top