Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API for PrintDlg 1

Status
Not open for further replies.

lexis7

Programmer
Sep 23, 2002
26
US
Hello!

I was trying to add a common dialog box for the print function to a command button(cmdPrint). I have read all about NOT using the commonn dialog box. I have also read tons about the saving/browsing of files using API. I cannot seem to find much info about the Print dialog box.

Does anyone have any suggestions on how to go about this.

I have tried some code but never really know where to put it all. Can somone be pretty specific about where all the code should go?

THANKS A MILLION FOR ANY HELP!
Alexis
 
To open the Print dialog up, you could just use SendKeys to simulate pressing Ctrl+P

Your code would look like this:

Private Sub cmdPrint_Click()

SendKeys "^p"

End Sub


Hope this helps


 
I CAN'T BELIEVE THAT WAS ALL THAT WAS REQUIRED!

I found all this code for calling the print dialog box and spent two days debugging all this code. It was seriously 5 pages of code.

Thank you for this wonderful suggestion, so simple!!!!

Have a great day!
 
Sending control & P may not always work. Also, there is no control over how the dialog looks.

try this code:

Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLGS) As Long

Type PRINTDLGS
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hDC As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type

Public Const PD_ALLPAGES = &H0
Public Const PD_SELECTION = &H1
Public Const PD_PAGENUMS = &H2
Public Const PD_NOSELECTION = &H4
Public Const PD_NOPAGENUMS = &H8
Public Const PD_COLLATE = &H10
Public Const PD_PRINTTOFILE = &H20
Public Const PD_PRINTSETUP = &H40
Public Const PD_NOWARNING = &H80
Public Const PD_RETURNDC = &H100
Public Const PD_RETURNIC = &H200
Public Const PD_RETURNDEFAULT = &H400
Public Const PD_SHOWHELP = &H800
Public Const PD_ENABLEPRINTTEMPLATE = &H4000
Public Const PD_ENABLESETUPTEMPLATE = &H8000
Public Const PD_ENABLEPRINTTEMPLATEHANDLE = &H10000
Public Const PD_ENABLESETUPTEMPLATEHANDLE = &H20000
Public Const PD_USEDEVMODECOPIES = &H40000
Public Const PD_USEDEVMODECOPIESANDCOLLATE = &H40000
Public Const PD_DISABLEPRINTTOFILE = &H80000
Public Const PD_HIDEPRINTTOFILE = &H100000
Public Const PD_NONETWORKBUTTON = &H200000

Public Function ShowPrinter() As Long
Dim PrintDialog AS PRINTDLGS

with PrintDialog
.hwndOwner = Access.hWndAccessApp
.lStructSize = Len(PrintDialog)
.flags=PD_DISABLEPRINTTOFILE+PD_ALLPAGES
end with

ShowPrinter = PrintDlg(PrintDialog)
End Function


Just call ShowPrinter to get your dialog. Changing the flags by summing the constants changes the options.


HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
lexis 7,


You could always use "DoCmd.RunCommand acCmdPrint" in your code. It calls the print dialog box.
 
This code is all great and wonderful, but I don't know what the "access" object in the function is. Could you please reply with the initialization or the code that defines the access object?
 
AFAIK Access is a built in object. (This code definately works on my A2k setup, but not tried it on A97) you could try using Application instead of Access.

HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top