Don't allow new record to be added from a form if a command buttin was not clicked

SteveL13
SteveL13 used Ask the Experts™
on
I have a form which has a command button on it.  This may seem strange but I do not want the user to be able to add a record from the form if the command button was not clicked while entering data in the current record.  I do want a message box to appear letting them know they have to click the command button.

However, the command button is only visible IF certain criteria was met in another field, a combobox field, on the form named "cboToWH".  The value in that combobox has to be "AT" (without the quotes in order for this event making the user click the command button to take place.

How can I do this?

--Steve
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
To further explain...  here is my code:

Private Sub cmdAddRec_Click()
On Error GoTo Err_cmdAddRec_Click
   
    If Me.cboToWH = "AT" And Me.chkbxRedButton.DefaultValue = False Then
        MsgBox "Since this is a shipment for Tijuana you must click the red button!"
        Me.chkbxRedButton.SetFocus
    End If
   
   
    DoCmd.RunCommand acCmdSaveRecord

    DoCmd.GoToRecord , , acNewRec
    Me.cboPartN.SetFocus
    Me.txtJobN.TabStop = False
    Me.txtDateEntered.TabStop = False
    Me.txtDateDue.TabStop = False
    Me.txtPOn.TabStop = False
    Me.cboToWH.TabStop = False
    Me.txtCarrier.TabStop = False
    Me.txtProN.TabStop = False
    Me.txtWHlocation = ""
    Me.Command67.Visible = False

Exit_cmdAddRec_Click:
    Exit Sub

Err_cmdAddRec_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddRec_Click
   
End Sub


So, after the "Me.chkbxRedButton.SetFocus" line I want the form to stop and wait for the user to click the command button.  How do I do this?
Analyst Assistant
Commented:
If the command button only becomes visible when they enter the required data how can they click it if they haven't?

Anyway, if you wanted that code to stop if they haven't entered the required data add Exit Sub after the SetFocus.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial