-
Nov 29th, 2008, 12:22 PM
#1
Thread Starter
Junior Member
[Access] How to specify printer for PrintOut method?
I am using Access 97 to print out the form.
I would like to have one command button whereby it can specify a canon printer to print the form and another command to use Microsoft office document image writer to save the same form as an image.
Code:
Private Sub Print_Click()
‘using canon printer to print the form
Docmd.PrintOut
End Sub
Private Sub Save_Click()
‘using Microsoft office document image writer to save the form as a .mdi file
Docmd.PrintOut’
End Sub
Is there a way to specify which printer to print the form?
Thanks
-
Nov 29th, 2008, 12:32 PM
#2
Re: [Access] How to specify printer for PrintOut method?
Set your printer before PrintOut command:
Code:
ActivePrinter = "Generic / Text Only" '<-- Replace with your printer name
-
Nov 29th, 2008, 10:23 PM
#3
Re: [Access] How to specify printer for PrintOut method?
dunno with access, but with excel you have to specify the port as well as the printer name
activeprinter = "someprinter on someport"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 30th, 2008, 05:52 PM
#4
Re: [Access] How to specify printer for PrintOut method?
Try this:
Code:
Private Sub Print_Click()
PrintTo "Adobe PDF" '-- replace with your Cannon printer DeviceName
End Sub
Private Sub Save_Click()
PrintTo "Microsoft Office Document Image Writer"
End Sub
Private Sub PrintTo(PrinterDeviceName As String)
Dim myCurPrinter As Printer
Set myCurPrinter = Me.Printer
Me.Printer = Application.Printers(PrinterDeviceName)
DoCmd.PrintOut
Set Me.Printer = myCurPrinter
End Sub
To get a list of all your printer DeviceNames, use this:
Code:
Sub AllMyPrinterDeviceNames()
Dim aPrinter As Printer
For Each aPrinter In Application.Printers
Debug.Print aPrinter.DeviceName
Next
End Sub
-
Dec 2nd, 2008, 10:01 AM
#5
Thread Starter
Junior Member
Re: [Access] How to specify printer for PrintOut method?
anhn,
a) PrintTo "Adobe PDF" '-- replace with your Cannon printer DeviceName
this cannot work as PrintTo need to be defined as a variable.
what should PrintTo dim as ?
b) Dim myCurPrinter As Printer
this also cannot work for A97 as there is an error (user-defined type not defined). A97 cannot dim variable as Printer
Pradeep1210,
c) ActivePrinter = "Generic / Text Only" '<-- Replace with your printer name
this also cannot work as what should ActivePrinter be dim as ?
thanks.
-
Dec 2nd, 2008, 11:20 AM
#6
Re: [Access] How to specify printer for PrintOut method?
Application.ActivePrinter = "Generic / Text Only"
-
Dec 2nd, 2008, 11:41 AM
#7
Re: [Access] How to specify printer for PrintOut method?
Sorry.. For access, it is Printer, not ActivePrinter
This is from Access help files.
This is how you set the active printer:
Code:
Dim prtDefault As Printer
Set Application.Printer = Application.Printers(0)
Set prtDefault = Application.Printer
With prtDefault
MsgBox "Device name: " & .DeviceName & vbCr _
& "Driver name: " & .DriverName & vbCr _
& "Port: " & .Port
End With
And this is how you can search for a specific printer:
Code:
Dim prtLoop As Printer
For Each prtLoop In Application.Printers
With prtLoop
MsgBox "Device name: " & .DeviceName & vbCr _
& "Driver name: " & .DriverName & vbCr _
& "Port: " & .Port
End With
Next prtLoop
Pradeep
Last edited by Pradeep1210; Dec 3rd, 2008 at 01:59 AM.
-
Dec 2nd, 2008, 03:24 PM
#8
Re: [Access] How to specify printer for PrintOut method?
this cannot work as PrintTo need to be defined as a variable.
what should PrintTo dim as ?
the printer name should be a string, you would need to save the devicename
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 2nd, 2008, 07:26 PM
#9
Re: [Access] How to specify printer for PrintOut method?
The code in post#4 does not work for Access-97.
With Access-97, it is much harder and perhaps there is only one way the code has to do is:
1. Save the system default printer name.
2. Change the system default printer to the printer you want to print to.
3. Print the form/report.
4. Reset the system default printer.
-
Dec 3rd, 2008, 10:43 AM
#10
Thread Starter
Junior Member
Re: [Access] How to specify printer for PrintOut method?
thanks all for your help
i think A97 will be harder to resolve while newer versions of access will be easier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|