Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i know if the user pressed "cancel" in a common dilalog box? 1

Status
Not open for further replies.

jamesa74

Programmer
Jan 10, 2001
20
IL
How can i know if the user pressed "cancel" in a open file common dilalog box?
 
You're using a Common Dialog control, right? If you set its CancelError property to True, it will raise a run-time error #32755 if the user cancels. Use an On Error statement to trap the error. Rick Sprague
 
Msg = "Do you want to request another Production File ?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
activeworkbooks = "C:\My Excel Files\macro_inputbox_production.xls"

GoTo showinputbox

Case vbNo
Cancel = True

GoTo shutinputbox
Exit Sub

Case vbCancel
Cancel = True
GoTo showinputbox'******tell it to do something here!!!
Exit Sub
End Select
 
I'm having the same problem, did what rick said, and now i get the error msg 32755, the error handler (on error resume next) dosen't catch it, I know im missing something so stupidly simple, but i dont have any idea what. Any advise?
Dragnut
 
can't you just test it like the sample i gave?
key-in on this part:

Case vbCancel
Cancel = True
GoTo showinputbox'******tell it to do something here!!!
 
To trap the error, just use this:
Code:
on error resume next
'whatever code is going to get you the 'desired' error
if err.number <> 0 then
  'whatever you want to do here
end if
err.clear
 
Dragnut, check your Tools>Options dialog, Advanced tab, to make sure you're using the Break on Unhandled Errors option. The other settings preempt your own error handling.
Rick Sprague
 
Thank you all guys. The reason it didn't work for me at first, and maybe it's the same for you dragnut is that i declared:
cdl.CancelError = True
after i opened the dialog box, and not before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top