473,734 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Common Dialog Print Trouble

devonknows
137 New Member
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 3136
Killer42
8,435 Recognized Expert Expert
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

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

Similar topics

2
22311
by: Patrick Herb | last post by:
Hello, I'm trying to print the content of a RichTextBox from my VB 6 app. What I want is that the CommonDialog shows up, the user selects a printer and the content of the RichTextBox prints to the selected printer. I'm not concerned about the text format. What I tried is something like this CommonDialog1.ShowPrinter
3
6800
by: S.W. Rasmussen | last post by:
With the risk of being accused of multi-posting I would like to draw the attention to a serious visual basic/windows issue discussed in the microsoft.public.vb.bugs newsgroup. As pointed out below by Norman Diamond the bug may result in loss of data when saving files with the standard common dialog control. Norman Diamond describes the problem as follows: ---------- In VB6 SP6, VB6 SP5, and possibly others, the common dialog box...
3
14839
by: deko | last post by:
I need to use the Common Dialog box, but I'm having trouble getting started. Bear with me as this is new ground for me... First, I get an error trying to declare these functions -- compile error: User-defined type not defined - am I missing a reference? which one? Private Declare Function GetOpenFileName _ Lib "COMDLG32.DLL" Alias "GetOpenFileNameA" _ (pOpenfilename As OPENFILENAME) As Long Private Declare Function GetSaveFileName _
23
7017
by: George | last post by:
Is there a way to customize the open file common dialog? I am trying to modify the button text so I can create a delete file common dialog. I need the same functionality of the open file common dialog but just need to change the button text from "open" to "delete". Any ideas? Thanks
2
1588
by: jcrouse | last post by:
In VB .Net is it possible to specify a location (x, y) for message boxes and the common dialog box class like you can do for windows forms? If so, how is this accomplished? Thank you, John
0
1373
by: Bo Gusman | last post by:
A curious problem, one that I think I've seen before. I have a .250 MLOC vb6 app that uses the common dialog control. If I select File/Open in my app to display the file open dialog and then alt-tab to another running app, when I try to alt-tab back to my app, the common dialog box and my apps main window is gone (can't see it in the task bar, or in the alt-tab window). If I then maximize another window and minimize it again, my app and...
6
1917
by: Steve Barnett | last post by:
I need to include a wizard in my application that will, as one of the steps, ask the user to select a file to open and (later) a file to save it as. The naff way to do this would be to have a button on the form that pops-up the common dialog. The cool way to do this would be to have the common dialog embedded in the wizard. I know it's possible, as I've seen other apps do this kind of thing, but I have no ideas how it can be achieved and...
0
1953
by: Cinfraco | last post by:
I am using Borland C++ and am having trouble finding documentation on how to use the print dialog. I currently have: if(PrintDialog->Execute()){ }else{ } I just need to write an array of about 100 strings to the printer that the user selected in the dialog box. Can anyone help??
1
2441
by: sirimanna | last post by:
I want to know how can i open some text file data using microsoft common dialog control.6 I know how to save text data using microsoft common dialog control.6 code are here, cdlfiles.filter="files(*.srt)\*.ami" cdlfiles.DefaultExt="str" cdlfiles.dialogTitle="save str notepad file" cdlfiles.DialogTitel=cdlOFNOverwritePrompt + cdlOFNPathmustexist on Error GoTo e cdlfiles.showsave
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.