If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Activating a Command Button on a Form
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. -- Sharon |
#2
|
|||
|
|||
Activating a Command Button on a Form
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 Slej wrote: 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. |
#3
|
|||
|
|||
Activating a Command Button on a Form
Rob,
You are my new best friend! This worked perfectly. Thanks. -- Sharon "Rob Parker" wrote: 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 Slej wrote: 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. . |
Thread Tools | |
Display Modes | |
|
|