Button activate yes no question to continue commands (1 Viewer)

Little_Anj

Registered User.
Local time
Tomorrow, 01:04
Joined
Dec 14, 2012
Messages
25
I have a button on my form, that runs a series of queries then closes the form.
It works great!!

How can I get the MsgBox feature to continue with all commands or cancel and close the form?

Here is my code without message box action

Code:
Private Sub AcceptChanges_Click()
DoCmd.SetWarnings False
Forms!SelectCustomerNewCustomerF!MergedRecordsF!CustomerID = Me.SecondID
Forms!SelectCustomerNewCustomerF!MergedRecordsF!MergedTo = Me.IDprimary
Forms!SelectPrimaryNewCustomerF!MergedRecordsF!UserID = Me.UserIdChange
DoEvents
DoCmd.OpenQuery "qryCloseMergedRecordUPDATE"
DoEvents
DoCmd.OpenQuery "qryPrimaryMergeAccountNoAPPEND"
DoEvents
DoCmd.OpenQuery "qryPrimaryMergeAccountNoUPDATE"
DoEvents
DoCmd.Close acForm, "SelectCustomerNewCustomerF"
DoCmd.SetWarnings True
End Sub

All of these actions work great, and do not need to be modified. it is just a msg box button to continue or cancel and close the form.
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:04
Joined
Aug 30, 2003
Messages
36,126
Look in help at the message box arguments. You want the yes and no buttons. You test for the user's selection and proceed accordingly.
 

Estuardo

Registered User.
Local time
Today, 16:04
Joined
May 27, 2003
Messages
134
G'd Afternoon,
May be i not following you... If you have a form with that button "AcceptChanges"
you want to execute all that code and at the same time a msgbox in front of the form with the options "Continue" & "Cancel"? You can't cancel a query execution without affecting the processed rows. The best you can do is to cancel the next query.

Switch the button's caption to "Cancel", once the button is clicked the first time. Set a module level boolean variable to control the flow. something like this:
Code:
Private bolCancel As boolean
Private Sub Form_Load()
    mbolCancel = False
    Me.AcceptChanges.Caption = "Accept Changes"
    
End Sub

Private Sub AcceptChanges_Click()
     
 DoCmd.SetWarnings False
    
If Not Me.btnCancel.Caption = "Cancel" Then
     Me.btnCancel.Caption = "Cancel"
Else
    mbolCancel = True
End If

Forms!SelectCustomerNewCustomerF!MergedRecordsF!CustomerID = Me.SecondID
Forms!SelectCustomerNewCustomerF!MergedRecordsF!MergedTo = Me.IDprimary
Forms!SelectPrimaryNewCustomerF!MergedRecordsF!UserID = Me.UserIdChange

If Not mbolCancel Then
      DoEvents
      DoCmd.OpenQuery "qryCloseMergedRecordUPDATE"
End If

If Not mbolCancel Then
      DoEvents
      DoCmd.OpenQuery "qryPrimaryMergeAccountNoAPPEND"
End If
If Not mbolCancel Then
      DoEvents
      DoCmd.OpenQuery "qryPrimaryMergeAccountNoUPDATE"
End If
If Not mbolCancel Then
      DoEvents
      DoCmd.Close acForm, "SelectCustomerNewCustomerF"
End If
DoCmd.Close acForm, "SelectCustomerNewCustomerF"

End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom