Update Code to add message cancel / continue

Gerrit.B

Board Regular
Joined
Aug 10, 2004
Messages
237
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a button with following code:

------------------------------------------------------------------------------------
Private Sub Update_Exchange_Rate_€_Click()
On Error GoTo Err_Update_Exchange_Rate_€_Click

Dim stDocName As String
DoCmd.SetWarnings False
stDocName = ChrW(85) & ChrW(112) & ChrW(100) & ChrW(97) & ChrW(116) & ChrW(101) & ChrW(69) & ChrW(120) & ChrW(99) & ChrW(104) & ChrW(97) & ChrW(110) & ChrW(103) & ChrW(101) & ChrW(82) & ChrW(97) & ChrW(116) & ChrW(101) & ChrW(8364)
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
Exit_Update_Exchange_Rate_€_Click:
Exit Sub

Err_Update_Exchange_Rate_€_Click:
MsgBox Err.Description
Resume Exit_Update_Exchange_Rate_€_Click

End Sub

------------------------------------------------------------------------------------

Where and what should I add to get a message with 2 options, Cancel or Continue.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi

Before this line :
DoCmd.SetWarnings False

insert this code :

Code:
    If MsgBox("Do you want to continue?", vbOKCancel, "Continue?") = vbCancel Then
        Exit Sub
    End If

Change the message to suit.

Also, you may want to move this line :
DoCmd.SetWarnings True

to after this line:
Exit_Update_Exchange_Rate_€_Click:

That way if there is an error and the code bombs then the warnings are turned back on.

HTH, Andrew
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,081
Members
451,738
Latest member
gaseremad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top