Remember KillDoc is to stop a printing in progress, Enddoc is when you have finished sending all data to the printer, it resets the printer and gets it ready for the next printing session.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
it is Still not working.Here is the code what i have written.Kindly help me.when i even cancel it still prints.any help would be Highly appreciated.here is the following code what i have
written.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
Set frm = Me.ActiveForm
If frm Is Nothing Then Exit Sub
'CommonDialog1.Action = 5
CommonDialog1.ShowPrinter
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
If Err Then
Printer.KillDoc
MsgBox "Dialog cancelled"
Exit Sub
End If
frm.GetTextBoxInvisible
frm.Refresh
frm.PrintForm
'CommonDialog1.ShowPrinter
frm.SetStartDesign
Printer.EndDoc
End Sub
Last edited by firoz.raj; Jul 11th, 2009 at 11:50 PM.
Here is the following code.still when i click prints it goes for print.here is the written code.Any help would be highly appreciated.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
Set frm = Me.ActiveForm
If frm Is Nothing Then Exit Sub
On Error GoTo btprint_Error
CommonDialog1.ShowPrinter
btprint_Error:
If Err Then
Printer.KillDoc
MsgBox "Dialog cancelled"
Exit Sub
End If
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True 'this will cause the control to generate error when cancel button is clicked
CommonDialog1.Orientation = cdlPortrait
frm.GetTextBoxInvisible
frm.Refresh
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign
End Sub
still not working .Here is the code what i have written.Kindly find the attachment also.any help would be highly appreciated.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
Set frm = Me.ActiveForm
If frm Is Nothing Then Exit Sub
frm.GetTextBoxInvisible
frm.Refresh
On Error GoTo btPrint_Error
'CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
'commondialog1.action=5
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
CommonDialog1.Orientation = cdlPortrait
CommonDialog1.ShowPrinter
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign
btPrint_Error:
MsgBox "dialog cancelled"
Exit Sub
End Sub
Resolved.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.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
Set frm = Me.ActiveForm
If frm Is Nothing Then Exit Sub
On Error GoTo btprint_Error
CommonDialog1.CancelError = True 'this will cause the control to generate error when cancel button is clicked
CommonDialog1.ShowPrinter
btprint_Error:
If Err.Number = 32755 Then
Printer.KillDoc
MsgBox "Dialog cancelled"
Exit Sub
End If
CommonDialog1.PrinterDefault = True
CommonDialog1.Orientation = cdlPortrait
frm.GetTextBoxInvisible
frm.Refresh
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign
End Sub
Last edited by firoz.raj; May 30th, 2011 at 02:10 PM.
Private Sub btPrint_Click()
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
End Sub
Its bound to carry on printing because you aren't trapping the Cancel button. You have put an error trap in with On Error GoTo btprint_Error but that doesn't really trap much because its in the wrong place. I see you've moved your error trap now. Then you've moved it back to the wrong place.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
On Error GoTo ErrHandler
Set frm = Me.ActiveForm
frm.GetTextBoxInvisible
frm.Refresh
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
CommonDialog1.Orientation = cdlPortrait
CommonDialog1.ShowPrinter
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign
Exit Sub 'You must blank of the error trap else it will be read as it goes through your code
ErrHandler:
If Err <> cdlCancel Then 'check for Cancel button else show the error
MsgBox Err.Description
'If its a printing error the stop printing
Printer.KillDoc
End If
End Sub
Your using If Err.Number = 32755 Then that number is the Cancel error number. There is no need to kill the printer or show a MsgBox saying "Dialog cancelled" because you haven't started printing anything yet.
Last edited by Keithuk; Jul 13th, 2009 at 07:22 AM.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
i want to show ms word printing dialog box .instead of old boredom notepad
printer dialog box.Kindly let me know the idea.any help would be highly appreciated.right know code is working properly.
Code:
Private Sub btPrint_Click()
Dim frm As IspecialForm
Set frm = Me.ActiveForm
If frm Is Nothing Then Exit Sub
On Error GoTo btprint_Error
CommonDialog1.PrinterDefault = True
CommonDialog1.Orientation = cdlPortrait
CommonDialog1.CancelError = True 'this will cause the control to generate error when cancel button is clicked
CommonDialog1.ShowPrinter
btprint_Error:
If Err.Number = 32755 Then
Exit Sub
End If
frm.GetTextBoxInvisible
frm.Refresh
frm.PrintForm
Printer.EndDoc
frm.SetStartDesign
Exit Sub
End Sub
Last edited by firoz.raj; May 30th, 2011 at 02:10 PM.
i want to show ms word printing dialog box .instead of old boredom notepad
printer dialog box.
I don't understand what you mean exactly ms word printing uses the similar CommonDialog but it uses comdlg32.dll API calls. I would think that NotePad uses exactly the same comdlg32.dll. Its only VB that uses comdlg32.ocx because its quick and simple.
Originally Posted by firoz.raj
Kindly let me know the idea.any help would be highly appreciated.right know code is working properly.
Haven't you tried my code yet?
Edit: Typo.
Last edited by Keithuk; Jul 13th, 2009 at 02:05 PM.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
But you will see sir ms notepad printer dialog box and ms word printer dialog
box is different.kindly let me know how should i implement commdlg.dll API calls .Any help would be highly
apperciated.
Last edited by firoz.raj; May 30th, 2011 at 02:10 PM.
But you will see sir ms notepad printer dialog box and ms word printer dialog
box is different.kindly let me know how should i implement commdlg.dll API calls .Any help would be highly
apperciated.
There is no CommonDialog for printing with NotePad only printer setup.
Here is a mCommonDialog.bas that I've removed from one of my apps. You will have to sort out how to call the different CommonDialog functions.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Can you tell me simple to call VBPrintDlg to a form.any help would be highly
appreciated.
Code:
Function VBPrintDlg(hdc As Long, Optional PrintRange As EPrintRange = eprAll, Optional DisablePageNumbers As Boolean, Optional FromPage As Long = 1, Optional ToPage As Long = &HFFFF, Optional DisableSelection As Boolean, Optional Copies As Integer, Optional ShowPrintToFile As Boolean, Optional DisablePrintToFile As Boolean = True, Optional PrintToFile As Boolean, Optional Collate As Boolean, Optional PreventWarning As Boolean, Optional Owner As Long, Optional Printer As Object, Optional flags As Long) As Boolean
Can you tell me simple to call VBPrintDlg to a form.any help would be highly
appreciated.
[/code]
I've had a look at the app again and the app doesn't use the print functions. Its an app for saving JPEG files which I downloaded from here.
I have other apps that use the comdlg32.dll API I shall have to do a search again. But I would say that all functions in the comdlg32.dll API are going to be exactly the same as comdlg32.ocx.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
How you are saying .dll for printing is also there.here is the code.Kindly tell
me how should i simple call this function.Kindly let me know any idea to call
this comdlg32.dll.any help would be highly appreciated.
Code:
Private Declare Function PrintDlg Lib "COMDLG32.DLL" Alias "PrintDlgA" (prtdlg As TPRINTDLG) As Integer
Public Enum EPrintDialog
PD_ALLPAGES = &H0
PD_SELECTION = &H1
PD_PAGENUMS = &H2
PD_NOSELECTION = &H4
PD_NOPAGENUMS = &H8
PD_COLLATE = &H10
PD_PRINTTOFILE = &H20
PD_PRINTSETUP = &H40
PD_NOWARNING = &H80
PD_RETURNDC = &H100
PD_RETURNIC = &H200
PD_RETURNDEFAULT = &H400
PD_SHOWHELP = &H800
PD_ENABLEPRINTHOOK = &H1000
PD_ENABLESETUPHOOK = &H2000
PD_ENABLEPRINTTEMPLATE = &H4000
PD_ENABLESETUPTEMPLATE = &H8000
PD_ENABLEPRINTTEMPLATEHANDLE = &H10000
PD_ENABLESETUPTEMPLATEHANDLE = &H20000
PD_USEDEVMODECOPIES = &H40000
PD_USEDEVMODECOPIESANDCOLLATE = &H40000
PD_DISABLEPRINTTOFILE = &H80000
PD_HIDEPRINTTOFILE = &H100000
PD_NONETWORKBUTTON = &H200000
End Enum
Private Type DEVNAMES
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
End Type
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Type DevMode
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
' New Win95 Page Setup dialogs are up to you
Private Type POINTL
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
TOp As Long
Right As Long
Bottom As Long
End Type
Private Type TPAGESETUPDLG
lStructSize As Long
hWndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTL
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As Long
hPageSetupTemplate As Long
End Type
' EPaperSize constants same as vbPRPS constants
Public Enum EPaperSize
epsLetter = 1 ' Letter, 8 1/2 x 11 in.
epsLetterSmall ' Letter Small, 8 1/2 x 11 in.
epsTabloid ' Tabloid, 11 x 17 in.
epsLedger ' Ledger, 17 x 11 in.
epsLegal ' Legal, 8 1/2 x 14 in.
epsStatement ' Statement, 5 1/2 x 8 1/2 in.
epsExecutive ' Executive, 7 1/2 x 10 1/2 in.
epsA3 ' A3, 297 x 420 mm
epsA4 ' A4, 210 x 297 mm
epsA4Small ' A4 Small, 210 x 297 mm
epsA5 ' A5, 148 x 210 mm
epsB4 ' B4, 250 x 354 mm
epsB5 ' B5, 182 x 257 mm
epsFolio ' Folio, 8 1/2 x 13 in.
epsQuarto ' Quarto, 215 x 275 mm
eps10x14 ' 10 x 14 in.
eps11x17 ' 11 x 17 in.
epsNote ' Note, 8 1/2 x 11 in.
epsEnv9 ' Envelope #9, 3 7/8 x 8 7/8 in.
epsEnv10 ' Envelope #10, 4 1/8 x 9 1/2 in.
epsEnv11 ' Envelope #11, 4 1/2 x 10 3/8 in.
epsEnv12 ' Envelope #12, 4 1/2 x 11 in.
epsEnv14 ' Envelope #14, 5 x 11 1/2 in.
epsCSheet ' C size sheet
epsDSheet ' D size sheet
epsESheet ' E size sheet
epsEnvDL ' Envelope DL, 110 x 220 mm
epsEnvC3 ' Envelope C3, 324 x 458 mm
epsEnvC4 ' Envelope C4, 229 x 324 mm
epsEnvC5 ' Envelope C5, 162 x 229 mm
epsEnvC6 ' Envelope C6, 114 x 162 mm
epsEnvC65 ' Envelope C65, 114 x 229 mm
epsEnvB4 ' Envelope B4, 250 x 353 mm
epsEnvB5 ' Envelope B5, 176 x 250 mm
epsEnvB6 ' Envelope B6, 176 x 125 mm
epsEnvItaly ' Envelope, 110 x 230 mm
epsenvmonarch ' Envelope Monarch, 3 7/8 x 7 1/2 in.
epsEnvPersonal ' Envelope, 3 5/8 x 6 1/2 in.
epsFanfoldUS ' U.S. Standard Fanfold, 14 7/8 x 11 in.
epsFanfoldStdGerman ' German Standard Fanfold, 8 1/2 x 12 in.
epsFanfoldLglGerman ' German Legal Fanfold, 8 1/2 x 13 in.
epsUser = 256 ' User-defined
End Enum
' EPrintQuality constants same as vbPRPQ constants
Public Enum EPrintQuality
epqDraft = -1
epqLow = -2
epqMedium = -3
epqHigh = -4
End Enum
Public Enum EOrientation
eoPortrait = 1
eoLandscape
End Enum
Private Declare Function PageSetupDlg Lib "COMDLG32" Alias "PageSetupDlgA" (lppage As TPAGESETUPDLG) As Boolean
Public Enum EPageSetup
PSD_Defaultminmargins = &H0 ' Default (printer's)
PSD_InWinIniIntlMeasure = &H0
PSD_MINMARGINS = &H1
PSD_MARGINS = &H2
PSD_INTHOUSANDTHSOFINCHES = &H4
PSD_INHUNDREDTHSOFMILLIMETERS = &H8
PSD_DISABLEMARGINS = &H10
PSD_DISABLEPRINTER = &H20
PSD_NoWarning = &H80
PSD_DISABLEORIENTATION = &H100
PSD_ReturnDefault = &H400
PSD_DISABLEPAPER = &H200
PSD_ShowHelp = &H800
PSD_EnablePageSetupHook = &H2000
PSD_EnablePageSetupTemplate = &H8000
PSD_EnablePageSetupTemplateHandle = &H20000
PSD_EnablePagePaintHook = &H40000
PSD_DisablePagePainting = &H80000
End Enum
Public Enum EPageSetupUnits
epsuInches
epsuMillimeters
End Enum
' Common dialog errors
How you are saying .dll for printing is also there.here is the code.Kindly tell
me how should i simple call this function.Kindly let me know any idea to call
this comdlg32.dll.any help would be highly appreciated.
Well as far as I know the comdlg32.dll calls are the same as the comdlg32.ocx calls.
I've just done a search on PSC and it only comes back with a couple of examples.
Common Dialog API calls and Display the Printer properites dialog box. The first one is the same code I've given you but with no examples. The second one only shows the Printer properties which isn't much help. There will be a lot of other apps on there that use the API calls, try a search.
I have apps that use the API but they only use the open and save file options. You may as well stick with the comdlg32.ocx, its quick and simple to use.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.