Activating a Command Button on a Form

S

Slej

SITUATION
I have an Orders Form with two command buttons: Pull Sheet & Packing Slip.
The form also has fields for the user to enter Order Date, Entered Date, and
Picked Date.

What I would like to do is, if all three date fields have dates in them,
then both command buttons are active; if certain combinations of the fields
are completed or not, then either one, both, or neither button is selectable.

I put the code below in the ON CURRENT for the form. This works well BUT,
it doesn't take effect until the user exists the current record then goes
back to it. For example, if a new order comes in and the Order Date and the
Entered Date are completed, the Pull Sheet button isn't selectable until that
record is left and then returned to.

Private Sub Form_Current()
If (Me.receivedate) >= #1/1/1900# And (Me.enterdate) >= #1/1/1900#
And (Me.pickdate) >= #1/1/1900# Then
Me.btnPullSheet.Enabled = True
Me.btnPackingSlip.Enabled = True
ElseIf (Me.receivedate) >= #1/1/1900# And (Me.enterdate) >=
#1/1/1900# Then
Me.btnPullSheet.Enabled = True
Me.btnPackingSlip.Enabled = False
Else
Me.btnPullSheet.Enabled = False
Me.btnPackingSlip.Enabled = False
End If
End Sub

QUESTION
Is there a way to code the form or the buttons or the date controls so that
the command buttons will immediately either become active or disabled without
having to exit the record? Thanks.
 
R

Rob Parker

You need to put this same code in the AfterUpdate event of each of the date
controls. Or, perhaps easier, call the Form_Current code in the AfterUpdate
events.

I'd also suggest that you use Not IsNull (Me.datefield), rather than
checking that the date is later than 1/1/1900.

HTH,

Rob
 

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