469,568 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Common Dialog Print Trouble

devonknows
137 100+
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. With dlgCommonDialog
  3. .DialogTitle = "Print"
  4. .DialogCancel = True
  5. .Flags = cdlPDReturnDC + cdlPDNoPageNums + cdlPDDisablePrintToFile + cdlPDNoSelection
  6. If rtfPrint.SelLength = 0 Then
  7.     .Flags = .Flags + cdlPDAllPages
  8. Else
  9.     .Flags = .Flags + cdlPDSelection
  10. End If
  11. If MsgBox("Are you sure you want to print everything in the list?", vbYesNo, "Confirm For Print") = vbYes Then
  12.     .ShowPrinter
  13.     If Err <> MSComDlg.cdlCancel Then
  14.          rtfPrint.SelPrint .hDC
  15.     End If
  16. End If
  17.  
Dec 21 '06 #1
1 2742
Killer42
8,435 Expert 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. With dlgCommonDialog
  2. .DialogTitle = "Print"
  3. .DialogCancel = True
  4. .Flags = cdlPDReturnDC + cdlPDNoPageNums + cdlPDDisablePrintToFile + cdlPDNoSelection
  5. If rtfPrint.SelLength = 0 Then
  6.     .Flags = .Flags + cdlPDAllPages
  7. Else
  8.     .Flags = .Flags + cdlPDSelection
  9. End If
  10. If MsgBox("Are you sure you want to print everything in the list?", vbYesNo, "Confirm For Print") = vbYes Then
  11.     .ShowPrinter
  12.     If Err <> MSComDlg.cdlCancel Then
  13.          rtfPrint.SelPrint .hDC
  14.     End If
  15. 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...
Expand|Select|Wrap|Line Numbers
  1. Dim LastError As Long
  2. On Error GoTo Oops
  3. With dlgCommonDialog
  4.   .DialogTitle = "Print"
  5.   .DialogCancel = True
  6.   .Flags = cdlPDReturnDC + cdlPDNoPageNums + cdlPDDisablePrintToFile + cdlPDNoSelection
  7.   If rtfPrint.SelLength = 0 Then
  8.     .Flags = .Flags + cdlPDAllPages
  9.   Else
  10.     .Flags = .Flags + cdlPDSelection
  11.   End If
  12.   If MsgBox("Are you sure you want to print everything in the list?", vbYesNo, "Confirm For Print") = vbYes Then
  13.     LastError = 0
  14.     .ShowPrinter
  15.     If LastError <> MSComDlg.cdlCancel Then
  16.       rtfPrint.SelPrint .hDC
  17.     End If
  18.   End If
  19. End With
  20. Exit Sub
  21. Oops:
  22.   LastError = Err.Number
  23.   Resume Next
  24.  
(Obviously I don't know how well this fits in with your code structure, but it's just to illustrate the idea.)
Dec 22 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Patrick Herb | last post: by
23 posts views Thread by George | last post: by
reply views Thread by Bo Gusman | last post: by
6 posts views Thread by Steve Barnett | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.