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!

Setting default printer

Status
Not open for further replies.

MDJ52

MIS
Mar 30, 2001
120
US
I am trying to use a module to control what printer I print to.
All of the examples I can find look as though they should work.
They require that you declare the variable as a type.
Ex: Dim X as Printer
This type is not defined anywhere that I can find.
What should I reference to use this Printer type.
Thanks
Mike.
 
Here's what works with Excel 2000 VBA, which should be pretty darn close for Access...

Dim xOrigPrtr As String, xNewPrtr As String
xOrigPrtr = Application.ActivePrinter
xNewPrtr = "ReptB on Ne00:"

When you want to change to the new printer you say:

Application.ActivePrinter = xNewPrtr

Changing back? As you'd imagine, it's simply

Application.ActivePrinter = xOrigPrtr


Note that this is how the printer port for this text only printer (ReptB) was defined in Win2000Pro. If your in 98 or Me it's different. In Win2000Pro, you can find out how the port is id'd through your registry, in 98 you can get it from the details section in your printer properties (I don't understand why it doesnt work like that in nt based windows).

You might do better running through all your printers and "file" printers (like distiller) and using the "local Variables" window in vba editor to see how each printer is addressed. You'd just set the printer you want to default, then set a string variable equal to Application.ActivePrinter, and check out that variable. Or maybe print out a msgbox with the current value of application.activeprinter
 
Hi!
There are codes for printer (and print) setup by using Common Dialog control. You may create Common Dialog control object on your form before running this codes. (MSCOMCTL.OCX)

Public intPrnOrient as Integer

Private Sub pbPrinter_Click()
On Error GoTo Err_pbPrinter_Click
Dim objDialog As Object
Dim BeginPage, EndPage, NumCopies, i

Set objDialog = Me.cmnDialog.Object 'cmnDialog >> Common dialog object name on form

With objDialog
.CancelError = True
.DialogTitle = "Printer Setup Sample"
.Orientation = iif(intPrnOrient =0,2,intPrnOrient )
.flags = 0 ' &H8 Or &H4 Or &H80000 Or &H0
.ShowPrinter
' Get user-selected values from the dialog box
BeginPage = .FromPage
EndPage = .ToPage
NumCopies = .Copies
intPrnOrient = .Orientation
For i = 1 To NumCopies
' Put code here to send data to the printer
Next i
End With

Exit_pbPrinter_Click:
Exit Sub

Err_pbPrinter_Click:
If Err.Number <> 32755 Then 'Cancel action
'MsgBox &quot;Error No &quot; & Err.Number & vbLf & Error$
End If
Resume Exit_pbPrinter_Click

End Sub

Aivars |-0

Look at help for .flags constants.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top