Capture or Identify Cancel Button on Excel Import

gopherking

Registered User.
Local time
Today, 03:21
Joined
May 26, 2011
Messages
31
I am using the following VBA code to call to the Import Excel process within Access:

DoCmd.RunCommand acCmdImportAttachExcel

I have recently identified that if a user clicks on the Cancel button on this screen that the other code I have beyond that displays a message that I don't want them to see. I would like to put in a catch that if the user clicks on Cancel that it will display another message before exiting without doing anything else. Does anyone know if there is a way to capture or identify if a user clicks on Cancel in VBA?

I understand that if you setup your own Message, you can specify vbCancel or vbOK just after it to help direct the right messages to your users. Just not sure if there is some built in code that I can reference in the same manner.
 
That would need to go into an IF statement of some sort.

IF vbCancel then
msgbox"You clicked cancel"
Exit Sub
Else what ever you want to do next

End IF
 
Thanks Trevor. I wasn't sure if the vbCancel was passed where I could use it in an IF statement as you suggested. Worked like a charm!
 

Users who are viewing this thread

Back
Top Bottom