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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test for 'Cancel' clicked in Common Dialog Control. How?

Status
Not open for further replies.

Sensibilium

Programmer
Apr 6, 2000
310
GB
I have a Common Dialog Control which is a 'Save As...' dialog, but if the user decides not to choose a filename and instead clicks the 'Cancel' button, an error occurs.<br><br>How do I trap for this error?<br><br>Thanks <p>ahdkaw<br><a href=mailto:ahdkaw@sensibilium.com>ahdkaw@sensibilium.com</a><br><a href= you do visit my sites - be warned! You must be of a discordian nature...'
 
When the error occurs, it should have a number.&nbsp;&nbsp;The cancel error on the Open dialog box is # 32755. So if your button was named cmdSave, then your code would look like this:<br><br>-----<br><br>Private Sub cmdSave_Click()<br>On Error GoTo Save_Err<br><br><br>&nbsp;&nbsp;&nbsp;' do all your code here<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Save_Exit:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br><br>Save_Err:<br>&nbsp;&nbsp;&nbsp;&nbsp;If Err.Number = <font color=red>32755</font> Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Resume Save_Exit<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox Err.Number & &quot;: &quot; & Err.Description<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Resume Save_Exit<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br><br>-----<br><br>Just make sure that the number in red is the same number that appears when the user clicks cancel. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Jimmy,<br><br>I'll try that but I'm not sure that that is the correct Error Number, as I have no actual event triggers on the ActiveX Common Dialog Control buttons.<br><br>I'll tell you if it works later...<br><br>Thanks <p>ahdkaw<br><a href=mailto:ahdkaw@sensibilium.com>ahdkaw@sensibilium.com</a><br><a href= you do visit my sites - be warned! You must be of a discordian nature...'
 
Thanks Jimmy, the Error Number you stated is the correct one, and it now works perfectly.<br><br>It should be noted however, that in order to make the Common Dialog generate an error on the clicking of the Cancel button, a Control Property called 'CancelError' must be set to 'Yes'<br><br>Hope that helps other people with a similar problem. <p>ahdkaw<br><a href=mailto:ahdkaw@sensibilium.com>ahdkaw@sensibilium.com</a><br><a href= you do visit my sites - be warned! You must be of a discordian nature...'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top