Good afternoon, ive got a common dialog which calles the print dialog, it prints perfectly, its prints my ListBox contents right, but when i click cancel on the print screen its just Prints it anyway and if i put the
.DialogCancel = True
in when i cancel it just causes an error and causes the debug menu you to come up, any help on this subject would be greatly appreciated. also any information you an give me to automatically setting the collate checkbox to 1, and only showing the default printer. if thatis possible.
again be most appreciative if anyone can help me with this.
Kind Regards
Devon.
- With dlgCommonDialog
-
.DialogTitle = "Print"
-
.DialogCancel = True
-
.Flags = cdlPDReturnDC + cdlPDNoPageNums + cdlPDDisablePrintToFile + cdlPDNoSelection
-
If rtfPrint.SelLength = 0 Then
-
.Flags = .Flags + cdlPDAllPages
-
Else
-
.Flags = .Flags + cdlPDSelection
-
End If
-
If MsgBox("Are you sure you want to print everything in the list?", vbYesNo, "Confirm For Print") = vbYes Then
-
.ShowPrinter
-
If Err <> MSComDlg.cdlCancel Then
-
rtfPrint.SelPrint .hDC
-
End If
-
End If
Hi.
Not sure about the collating and so on. But as for the cancel, I think that is the expected behaviour. In the version of the commoon dialog control I'm using, the property is actually called
.CancelError. The idea is to produce a trappable error, so you can handle it in your code.
You need to use the
On Error statement to deal with it. There are a coupe of options. You could just say
On Error Resume Next, which will then allow you to check Err as your code says now. If you don't want to enter debug mode when it happens (this only applies when running in the IDE, of course) then in
Options, under the
General tab, set
Error Trapping to
Break on Unhandled Errors.
Here's another option...
- Dim LastError As Long
-
On Error GoTo Oops
-
With dlgCommonDialog
-
.DialogTitle = "Print"
-
.DialogCancel = True
-
.Flags = cdlPDReturnDC + cdlPDNoPageNums + cdlPDDisablePrintToFile + cdlPDNoSelection
-
If rtfPrint.SelLength = 0 Then
-
.Flags = .Flags + cdlPDAllPages
-
Else
-
.Flags = .Flags + cdlPDSelection
-
End If
-
If MsgBox("Are you sure you want to print everything in the list?", vbYesNo, "Confirm For Print") = vbYes Then
-
LastError = 0
-
.ShowPrinter
-
If LastError <> MSComDlg.cdlCancel Then
-
rtfPrint.SelPrint .hDC
-
End If
-
End If
-
End With
- Exit Sub
-
Oops:
-
LastError = Err.Number
-
Resume Next
-
(Obviously I don't know how well this fits in with your code structure, but it's just to illustrate the idea.)