Hi, I am displaying a dialogbox to the user. If the user clicks the "Cancel" button I want to show a message box, then I want to continue displaying the dialogbox. The best I can come up with is...

Do
comdia.Filter = "*.doc"
comdia.InitDir = "C:\"
comdia.filename = "file01"
comdia.ShowSave
On Error GoTo cancelmessage
cancelmessage:
MsgBox "You must save this document."
Loop Until comdia.filename <> ""

But it ain't working. And ideas out there? Thanks.

Recommended Answers

All 5 Replies

Okay I've now got the following code...

Do
On Error GoTo cancelmessage
comdia.cancelerror = True
comdia.Filter = "*.doc"
comdia.InitDir = "C:\"
comdia.filename = ""
comdia.ShowSave

cancelmessage:
Select Case Err
Case 32755
MsgBox "You must save this document."
Err.Clear
End Select
Loop Until comdia.filename <> ""

When I click the "Cancel" button (for the first time) the message box appears and then, after I click "OK" on the message box, the dialog box is displayed. But, when I click the "Cancel" button again, I get an error...

"Run-time error "32755" Cancel was selected."

And in my code "comdia.ShowSave" is highlighted.

Anyone?

You might be confused by the fact that the logic following "cancelmessage:" is executed regardless of whether or not there is an error.

The second time through the loop, you may have gotten an error other than 32755. In this case the "Err.Clear" instruction would not have been executed.

Try putting a "goto endloop" statement after the "comdia.ShowSave" and an "endloop:" statement after the "Loop Until..." statement.

Hoppy

You might be confused by the fact that the logic following "cancelmessage:" is executed regardless of whether or not there is an error.

Yeah, error trapping is not the easiest thing in the world. BTW, is there an easier way to do this (e.g. if cancel = "" then)???

The second time through the loop, you may have gotten an error other than 32755. In this case the "Err.Clear" instruction would not have been executed.

Hmmm, how can another error be created even though I was clicking on the Cancel button? What am I missing?

Try putting a "goto endloop" statement after the "comdia.ShowSave" and an "endloop:" statement after the "Loop Until..." statement.

If you mean like this, it still generates the same error.

Do
On Error GoTo cancelmessage
comdia.cancelerror = True
comdia.Filter = "*.doc"
comdia.InitDir = "C:\"
comdia.filename = ""
comdia.ShowSave
On Error GoTo endloop

cancelmessage:
Select Case Err
Case 32755
MsgBox "You must save this document."
Err.Clear
End Select
Loop Until comdia.filename <> ""
endloop:
Err.Clear

Thanks for the reply Hoppy.

You are still always going to "cancelmessage:". try the following code:

Do
On Error GoTo cancelmessage
comdia.cancelerror = True
comdia.Filter = "*.doc"
comdia.InitDir = "C:\"
comdia.filename = ""
comdia.ShowSave
GoTo endloop

cancelmessage:
Select Case Err
Case 32755
MsgBox "You must save this document."
Err.Clear
End Select
Loop Until comdia.filename <> ""
endloop:
Err.Clear

Hooray, I think I've finally worked it out...

The code below displays a "Save As" dialog box. It then shows a message box if the user clicks on the Cancel button (or if they try and close the dialog box.) Then it continues to show the "Save As" dialog box, until a valid filename is entered and the user clicks the Save button. I can't see any problems with the code yet, but if there are any problems, I'll post here again.

Thanks once again for your help Hoppy, it kept me motivated :)

Do
comdia.Filter = "*.doc"
comdia.InitDir = "C:\"
comdia.CancelError = True
    If Err.Number = 32755 Then
    Err.Clear
    MsgBox "You must save this document."
    End If
On Error Resume Next
comdia.ShowSave
Loop Until comdia.filename <> ""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.