How to Activate Command Button When Two Combos Are Not Null

D

DOYLE60

I have two combo boxes on a print dialog form that must not be null for a
report to print. I want the Print Command Button to be disabled until the two
combos are filled in by the user. The user can fill the combos in any order.

I wrote code for this and put it in the After Change event of each combo. It
didn't work because the database didn't recognize the choice currently made by
the user, believing that combo still to be null.

What is the easiest code for this?

Thanks,

Matt
 
B

Bas Cost Budde

DOYLE60 said:
I have two combo boxes on a print dialog form that must not be null for a
report to print. I want the Print Command Button to be disabled until the two
combos are filled in by the user. The user can fill the combos in any order.

I wrote code for this and put it in the After Change event of each combo. It
didn't work because the database didn't recognize the choice currently made by
the user, believing that combo still to be null.

What is the easiest code for this?

The Click event will fire when a choice is made. AfterUpdate, I think,
fires only for bound controls. But don't pin me on that last one.
 
G

Guest

Matt:

How do you know that Access still thinks that your comboboxes are still
empty? What code did you use to check that?
First, go to your code for the After_Change event. Put in a MsgBox
command to alert you that you're executing where you want to be. Determine
if the combobox has a selection by looking at the Listindex property for that
combobox, something like IF COMBOBOX.LISTINDEX>0 THEN DOSOMETHING.
Since you stated that the comboboxes can be filled in any order, your
bigger problem is determing when both have been filled. So, each event
procedure (for the two boxes) will need to cross-check the Listindex values
from each other so that you know when both are done. Each procedure will
have the ability to enable the Print button for the user.

Steve in Ohio
 
D

DOYLE60

How do you know that Access still thinks that your comboboxes are still
empty? What code did you use to check that?

I simply typed one of the lines with a typo. When it gave me an error on that
one, I knew, logically, that it went through the If-then statement incorrectly,
or not as I thought it should have. My code, which is on another computer was
something like this:

If Combo1 = "" than
If Combo2 = "" than
Button1.enabled = False
Else
Button1.enabled = False
End if
Else
If Combo2 is null than
Button1.enabled = False
Else
Button1.enabled = True
End if
End if

That is from memory and may have some obvious problem. Anyway, I did it
something like that after trying something easier at first.

Thanks.

Matt
 
D

DOYLE60

No the Click event doesn't work either for this code.

If Combo42 = "" Then
If Combo43 = "" Then
Command44.Enabled = False
Else
Command44.Enabled = False
End If
Else
If Combo43 = "" Then
Command44.Enabled = False
Else
Command44.Enabled = True
End If
End If

To review, I want two unbound combos to enable a command button only when both
combos are not null. Thanks,

Matt
 
B

Bas Cost Budde

DOYLE60 said:
No the Click event doesn't work either for this code.

If Combo42 = "" Then
If Combo43 = "" Then
Command44.Enabled = False
Else
Command44.Enabled = False
End If
Else
If Combo43 = "" Then
Command44.Enabled = False
Else
Command44.Enabled = True
End If
End If

To review, I want two unbound combos to enable a command button only when both
combos are not null. Thanks,

Ahh. If you want to test for 'not null', that is what you should code.

If IsNull(combo42) then

etc

Null means "don't know" and is that ever the same as ""? I doubt it, but
who will tell?
 
B

Bas Cost Budde

DOYLE60 said:
I have two combo boxes on a print dialog form that must not be null for a
report to print. I want the Print Command Button to be disabled until the two
combos are filled in by the user. The user can fill the combos in any order.
As a matter of fact, you can have this in both the whatever-handlers for
these comboboxes:

printbuttonname.enabled=not isnull(combobox1) and not isnull(combobox2)

I suggest you name those controls something instead of combo43 and
command44 :)
 
J

John Spencer (MVP)

If you only have the three controls on the form, then you have a problem. Since
the button's enabled property won't update automatically when you attempt to
leave one of the combobox controls and move to the button if it is disabled.

You can overcome this by using a timer event, which i don't really like. You
can add a second button (real button) on top of the button (dummy button) you
wish to disable and set the second button's transparent property to true and use
the code in that button to perform whatever action you need.

Use the afterupdate event of the comboboxes to enable/disable the dummy button.

Use code in the real button to actually do the work.

Code would look something like this AIR CODE

Private Sub x()
Me.btnDummy.Enabled = Not (IsNull(Combo1) Or IsNull(Combo3))
End Sub

Private Sub Combo1_AfterUpdate()
Call x
End Sub

Private Sub Combo3_AfterUpdate()
Call x
End Sub

Private Sub BtnReal_GotFocus()
If Me.btnDummy.Enabled = True Then
MsgBox "Button pressed"
Else
'do Nothing
End If
End Sub
 

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