Printing using Print dialog box

Reply

Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Printing using Print dialog box

 
0
  #1
Jul 11th, 2009
when i press cancel button.it still prints.Kindly let me know .any help would be Highly appreciated.here is the following code what i have written.
  1. Private Sub btPrint_Click()
  2. Dim frm As IspecialForm
  3. Set frm = Me.ActiveForm
  4. frm.GetTextBoxInvisible
  5. frm.Refresh
  6. 'CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
  7. CommonDialog1.Action = 5
  8. CommonDialog1.PrinterDefault = True
  9. CommonDialog1.CancelError = True
  10. CommonDialog1.Orientation = cdlPortrait
  11. CommonDialog1.ShowPrinter
  12. frm.PrintForm
  13. Printer.EndDoc
  14. frm.SetStartDesign
  15. End Sub
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,108
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 91
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Printing using Print dialog box

 
0
  #2
Jul 12th, 2009
how about adding an if statement like:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. if CommonDialog1.CancelError = True then
  2. exit sub
  3. end if
just a suggestion maybe other guys around here got a better solution

Goodluck!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 826
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 150
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark

Re: Printing using Print dialog box

 
0
  #3
Jul 13th, 2009
Actually cguan_77 you are not far off...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btPrint_Click()
  2.  
  3. On Error GoTo btPrint_ClickError
  4.  
  5. Dim frm As IspecialForm
  6. Set frm = Me.ActiveForm
  7. frm.GetTextBoxInvisible
  8. frm.Refresh
  9. 'CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
  10. CommonDialog1.Action = 5
  11. CommonDialog1.PrinterDefault = True
  12. CommonDialog1.CancelError = True
  13. CommonDialog1.Orientation = cdlPortrait
  14. CommonDialog1.ShowPrinter
  15. frm.PrintForm
  16. Printer.EndDoc
  17. frm.SetStartDesign
  18.  
  19. Exit Sub
  20. btPrint_ClickError:
  21.  
  22. If Err.Number = 32755 Then Exit Sub 'User Pressed Cancel
  23.  
  24. MsgBox "btPrint_Click " & Err.Number & ":" & Err.Description
  25.  
  26. End Sub

The reason it is still printing is because you had no error handler.


Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Printing using Print dialog box

 
0
  #4
Jul 13th, 2009
Thank you VB5 Programmer.right now it is working .for printer ms word printer dialog box is not possible?.Kindly let me know.Any help would be Highly Appreciated.the following code is working fine.ms word printer dialog box is not possible instead of terrible boredom Notepad Printer dialog box.Kindly let me know.the following code is working fine.
fine.
  1. Private Sub btPrint_Click()
  2. Dim frm As IspecialForm
  3. Set frm = Me.ActiveForm
  4. If frm Is Nothing Then Exit Sub
  5. On Error GoTo btprint_Error
  6. CommonDialog1.CancelError = True 'this will cause the control to generate error when cancel button is clicked
  7. CommonDialog1.ShowPrinter
  8. btprint_Error:
  9. If Err.Number = 32755 Then
  10. Printer.KillDoc
  11. MsgBox "Dialog cancelled"
  12. Exit Sub
  13. End If
  14. CommonDialog1.PrinterDefault = True
  15. CommonDialog1.Orientation = cdlPortrait
  16. frm.GetTextBoxInvisible
  17. frm.Refresh
  18. frm.PrintForm
  19. Printer.EndDoc
  20. frm.SetStartDesign
  21. End Sub
Attached Files
File Type: zip Printer.zip (26.8 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Printing using Print dialog box

 
0
  #5
Jul 14th, 2009
now i want to call this printer dialog box.when user click at print
button .Kindly let me know the idea.how should i call this print
dialog box .using print button.Kindly help me.any help would be
Greatly appreciated.here is the following code.i want to call this
dll function at print buttton.Kindly find the attachment also.
  1. Private Declare Function PrintDlg Lib "COMDLG32.DLL" Alias "PrintDlgA" (prtdlg As TPRINTDLG) As Integer
  2.  
  3. Public Enum EPrintDialog
  4. PD_ALLPAGES = &H0
  5. PD_SELECTION = &H1
  6. PD_PAGENUMS = &H2
  7. PD_NOSELECTION = &H4
  8. PD_NOPAGENUMS = &H8
  9. PD_COLLATE = &H10
  10. PD_PRINTTOFILE = &H20
  11. PD_PRINTSETUP = &H40
  12. PD_NOWARNING = &H80
  13. PD_RETURNDC = &H100
  14. PD_RETURNIC = &H200
  15. PD_RETURNDEFAULT = &H400
  16. PD_SHOWHELP = &H800
  17. PD_ENABLEPRINTHOOK = &H1000
  18. PD_ENABLESETUPHOOK = &H2000
  19. PD_ENABLEPRINTTEMPLATE = &H4000
  20. PD_ENABLESETUPTEMPLATE = &H8000
  21. PD_ENABLEPRINTTEMPLATEHANDLE = &H10000
  22. PD_ENABLESETUPTEMPLATEHANDLE = &H20000
  23. PD_USEDEVMODECOPIES = &H40000
  24. PD_USEDEVMODECOPIESANDCOLLATE = &H40000
  25. PD_DISABLEPRINTTOFILE = &H80000
  26. PD_HIDEPRINTTOFILE = &H100000
  27. PD_NONETWORKBUTTON = &H200000
  28. End Enum
  29.  
  30. Private Type DEVNAMES
  31. wDriverOffset As Integer
  32. wDeviceOffset As Integer
  33. wOutputOffset As Integer
  34. wDefault As Integer
  35. End Type
  36.  
  37. Private Const CCHDEVICENAME = 32
  38. Private Const CCHFORMNAME = 32
  39.  
  40. Private Type DevMode
  41. dmDeviceName As String * CCHDEVICENAME
  42. dmSpecVersion As Integer
  43. dmDriverVersion As Integer
  44. dmSize As Integer
  45. dmDriverExtra As Integer
  46. dmFields As Long
  47. dmOrientation As Integer
  48. dmPaperSize As Integer
  49. dmPaperLength As Integer
  50. dmPaperWidth As Integer
  51. dmScale As Integer
  52. dmCopies As Integer
  53. dmDefaultSource As Integer
  54. dmPrintQuality As Integer
  55. dmColor As Integer
  56. dmDuplex As Integer
  57. dmYResolution As Integer
  58. dmTTOption As Integer
  59. dmCollate As Integer
  60. dmFormName As String * CCHFORMNAME
  61. dmUnusedPadding As Integer
  62. dmBitsPerPel As Integer
  63. dmPelsWidth As Long
  64. dmPelsHeight As Long
  65. dmDisplayFlags As Long
  66. dmDisplayFrequency As Long
  67. End Type
  68.  
  69. ' New Win95 Page Setup dialogs are up to you
  70. Private Type POINTL
  71. X As Long
  72. Y As Long
  73. End Type
  74.  
  75. Private Type RECT
  76. Left As Long
  77. TOp As Long
  78. Right As Long
  79. Bottom As Long
  80. End Type
  81.  
  82. Private Type TPAGESETUPDLG
  83. lStructSize As Long
  84. hWndOwner As Long
  85. hDevMode As Long
  86. hDevNames As Long
  87. flags As Long
  88. ptPaperSize As POINTL
  89. rtMinMargin As RECT
  90. rtMargin As RECT
  91. hInstance As Long
  92. lCustData As Long
  93. lpfnPageSetupHook As Long
  94. lpfnPagePaintHook As Long
  95. lpPageSetupTemplateName As Long
  96. hPageSetupTemplate As Long
  97. End Type
  98.  
  99. ' EPaperSize constants same as vbPRPS constants
  100. Public Enum EPaperSize
  101. epsLetter = 1 ' Letter, 8 1/2 x 11 in.
  102. epsLetterSmall ' Letter Small, 8 1/2 x 11 in.
  103. epsTabloid ' Tabloid, 11 x 17 in.
  104. epsLedger ' Ledger, 17 x 11 in.
  105. epsLegal ' Legal, 8 1/2 x 14 in.
  106. epsStatement ' Statement, 5 1/2 x 8 1/2 in.
  107. epsExecutive ' Executive, 7 1/2 x 10 1/2 in.
  108. epsA3 ' A3, 297 x 420 mm
  109. epsA4 ' A4, 210 x 297 mm
  110. epsA4Small ' A4 Small, 210 x 297 mm
  111. epsA5 ' A5, 148 x 210 mm
  112. epsB4 ' B4, 250 x 354 mm
  113. epsB5 ' B5, 182 x 257 mm
  114. epsFolio ' Folio, 8 1/2 x 13 in.
  115. epsQuarto ' Quarto, 215 x 275 mm
  116. eps10x14 ' 10 x 14 in.
  117. eps11x17 ' 11 x 17 in.
  118. epsNote ' Note, 8 1/2 x 11 in.
  119. epsEnv9 ' Envelope #9, 3 7/8 x 8 7/8 in.
  120. epsEnv10 ' Envelope #10, 4 1/8 x 9 1/2 in.
  121. epsEnv11 ' Envelope #11, 4 1/2 x 10 3/8 in.
  122. epsEnv12 ' Envelope #12, 4 1/2 x 11 in.
  123. epsEnv14 ' Envelope #14, 5 x 11 1/2 in.
  124. epsCSheet ' C size sheet
  125. epsDSheet ' D size sheet
  126. epsESheet ' E size sheet
  127. epsEnvDL ' Envelope DL, 110 x 220 mm
  128. epsEnvC3 ' Envelope C3, 324 x 458 mm
  129. epsEnvC4 ' Envelope C4, 229 x 324 mm
  130. epsEnvC5 ' Envelope C5, 162 x 229 mm
  131. epsEnvC6 ' Envelope C6, 114 x 162 mm
  132. epsEnvC65 ' Envelope C65, 114 x 229 mm
  133. epsEnvB4 ' Envelope B4, 250 x 353 mm
  134. epsEnvB5 ' Envelope B5, 176 x 250 mm
  135. epsEnvB6 ' Envelope B6, 176 x 125 mm
  136. epsEnvItaly ' Envelope, 110 x 230 mm
  137. epsenvmonarch ' Envelope Monarch, 3 7/8 x 7 1/2 in.
  138. epsEnvPersonal ' Envelope, 3 5/8 x 6 1/2 in.
  139. epsFanfoldUS ' U.S. Standard Fanfold, 14 7/8 x 11 in.
  140. epsFanfoldStdGerman ' German Standard Fanfold, 8 1/2 x 12 in.
  141. epsFanfoldLglGerman ' German Legal Fanfold, 8 1/2 x 13 in.
  142. epsUser = 256 ' User-defined
  143. End Enum
  144.  
  145. ' EPrintQuality constants same as vbPRPQ constants
  146. Public Enum EPrintQuality
  147. epqDraft = -1
  148. epqLow = -2
  149. epqMedium = -3
  150. epqHigh = -4
  151. End Enum
  152.  
  153. Public Enum EOrientation
  154. eoPortrait = 1
  155. eoLandscape
  156. End Enum
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: jinnie_gia is an unknown quantity at this point 
Solved Threads: 0
jinnie_gia jinnie_gia is offline Offline
Newbie Poster

Re: Printing using Print dialog box

 
0
  #6
Jul 14th, 2009
Private Sub btPrint_Click()

On Error GoTo On_ClickError

Dim frm As IspecialForm
Set frm = Me.ActiveForm
frm.GetTextBoxInvisible
frm.Refresh
'CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
CommonDialog1.Action = 5
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
CommonDialog1.Orientation = cdlPortrait
CommonDialog1.ShowPrinter
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign

Exit Sub
On_ClickError:

If Err.Number = 32755 Then Exit Sub 'User Pressed Cancel

MsgBox "btPrint_Click " & Err.Number & ":" & Err.Description

MsgBox “Printing Stopped”

End Sub

================================================
Originally Posted by firoz.raj View Post
when i press cancel button.it still prints.Kindly let me know .any help would be Highly appreciated.here is the following code what i have written.
  1. Private Sub btPrint_Click()
  2. Dim frm As IspecialForm
  3. Set frm = Me.ActiveForm
  4. frm.GetTextBoxInvisible
  5. frm.Refresh
  6. 'CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
  7. CommonDialog1.Action = 5
  8. CommonDialog1.PrinterDefault = True
  9. CommonDialog1.CancelError = True
  10. CommonDialog1.Orientation = cdlPortrait
  11. CommonDialog1.ShowPrinter
  12. frm.PrintForm
  13. Printer.EndDoc
  14. frm.SetStartDesign
  15. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Printing using Print dialog box

 
0
  #7
Jul 15th, 2009
i want to call Private Declare Function PrintDlg Lib "COMDLG32.DLL"
instead of print dialog box.Kindly let me know .any help would be
highly appreciated.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC