|
-
Nov 1st, 2000, 11:35 PM
#1
Thread Starter
New Member
Using the CommonDialog control to display a Print dialog, how do you determine whether the user has clicked 'Cancel' or 'OK'. (i.e. Nothing should print if they hit cancel.)
-
Nov 2nd, 2000, 12:24 AM
#2
PowerPoster
The way I would do it, which isn't usually the most efficient is to use this code if you are using a command button to print the file:
Code:
Private Sub cmdPrint_Click()
On Error GoTo errorline 'skip the commondialog code
'your commondialog code here
Exit Sub 'exit the sub incase they pressed OK
errorline: 'declare the error line
msgbox "You canceled the print command..." 'you can delete this msgbox code
'and nothing will happen when the button
' is pressed, like most programs.
End Sub
-
Nov 2nd, 2000, 02:44 PM
#3
Fanatic Member
If you're using the common dialog control, set its CancelError property to true, then you can check the Err object. If you hit a cancel button in the common dialog with CancelError = True, Err.Number = cdlCancel. This is a better way to check it since you won't catch every single error at once, only the cancel one (although you should check for general errors too). If that seems clear as mud, here's a little snip from an open command in a prog of mine:
Code:
Public Sub OpenFile()
Dim FileName As String
mdiText.dlgDialog.DialogTitle = "Open File"
mdiText.dlgDialog.Flags = cdlOpenFileFlags
mdiText.dlgDialog.Filter = cdlFilter
mdiText.dlgDialog.FilterIndex = 1
mdiText.dlgDialog.CancelError = True
On Error Resume Next
mdiText.dlgDialog.ShowOpen
'specific check for the Cancel button being pressed
If Err.Number = cdlCancel Then Exit Sub
FileName = mdiText.dlgDialog.FileName
'resume with normal events of program since there was a valid filename selected
Hope this helps you.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Nov 3rd, 2000, 09:06 AM
#4
Addicted Member
Here's a simple way that I used to print and was able to cancel the printing when the cancel button was clicked.
Private sub mnuFilePrint_Click()
on local error goto printerror
commondialog1.cancelerror = true
commondialog1.flags = cdlpdallpages + cdlpdreturndc
commondialog1.showprinter
'put what needs to be printed here.
printerror:
printer.enddoc
end sub
hope this helps.
-
Nov 3rd, 2000, 10:51 AM
#5
Importan !!!!!!!!!!!!!!!!!
Hi
You can forget to use the common dialog for printer change!!!!!!!!!!!!
Microsoft have a big bug in this control!!! because if you change any property of the printer with the common dialog it will be ignorred!!.
If you want you can have an class modul from me. It work with api- calls and you don't need the common dialog control.
send me a mail to [email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|