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

Common Dialog problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
In a commondialog how can I detect if a user pressed the cancel button? What is the error that is generated and how can I trap it?

I have:

CommonDialog1.ShowOpen
txt2 = CommonDialog1.FileName
OLE2.CreateEmbed (txt2)

Of course if the user presses cancel the 2nd line will also be read and I'll get an error because there is nothing on txt2!! How can do something like:

CommonDialog1.ShowOpen
txt2 = CommonDialog1.FileName

If user Didnt_Press_Cancel then
OLE2.CreateEmbed (txt2)
End if

I'd like to do something like this, but don't have the knowledge to do it can anyone help?
 
Thank you for your reply.
I've allready tryed that, but after that what can I do? I'm just starting with VB so I guess this should sound basic but for me it isn't... How can I avoid the OLE2.CreateEmbed (txt2) line to be runned if the user presses Cancel?

Thanx.
 
repeat
CD.showopen
filename = CD.filename
until filename <> &quot;&quot;

i find this useful... it keeps asking until they select a file

 
To avoid the OLE2 line being run, put the following error handling statement before the .Showopen statement:

On Error GoTo ErrHandler

then at the bottom of the procedure:

Exit Sub

ErrHandler:

' User pressed the Cancel button

End Sub

This will capture the Cancel button and go directly to the end of the procedure without processing any other lines.

Madlarry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top