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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Printer issues.

Status
Not open for further replies.

joejack0330

Technical User
Jan 27, 2006
95
US
We have a form that has some buttons to print invoices and when the user presses print button it changes the default printer then prints report. We have multiple printers in table so it goes back and forth to different printers so we need to change default rather than assigning specific in page setup. This worked well under Access 2000 but since going to 2007, it seems to be a problem. I've played around a lot and seem to have it narrowed down to where even though code seems to be changing default printer, access seems to still think that the default printer is the printer that was default when Access was opened. I've paused execution and can see the default printer changing correctly but if I do a print preview then go to print, it still displays original default as the choice in list of printers. Is there a way to force a refresh of database without closing down and opening again or maybe a way to assign specific, not default, in vba code? Thanks, Joe
 
Update: I think I found a solution in case anyone else comes across this problem. Before setting the default printer in vba code, I set the application printer to nothing as in example below:

Dim dr As aht_tagDeviceRec
Dim intRetval As Integer
Dim ctl As Control
Dim drDefaultPrinterBuffer As String drDefaultPrinterBuffer=ahtGetINIString"Windows", "Device")
Set ctl = Forms!frmMainMenu!cboLaserPrinters
With dr
.drDeviceName = ctl.Column(1)
.drDriverName = ctl.Column(2)
End With
Application.Printer = Nothing
intRetval = ahtSetDefaultPrinter(dr)
stDocName = "rptInvoicePrinted"
DoCmd.OpenReport stDocName, acViewNormal, "", ""
intRetval = True
intRetval = (aht_apiWriteProfileString("Windows", _
"Device", drDefaultPrinterBuffer) <> 0)
 
You can try fiddeling with this code:

Function GetDefPrinter()
GetDefPrinter = Application.Printer.DeviceName
End Function
Function SetDefPrtAccess(PrinterName As String)
Application.Printer = Application.Printers(PrinterName)
End Function
Sub SetDefPrinter(PrinterName As String)
SetDefaultPrinter PrinterName
End Sub
Sub SetPrtTst()
SetDefPrinter "OKI C5100"
SetDefPrinter "HP LaserJet 4M Plus"
End Sub

Should even in Access 07 (worst access ever)

Herman
Say no to macros
 
Are you running the latest service pack? This was an Access bug that was fixed in SP2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top