Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Can't open Access reports with default printer

Posted on 2010-08-24
Medium Priority
Last Modified: 2013-11-28
This question is very similatr to the the problem stated in:

I have a program that people use on various PCs. The actual printers will be network printers but vary depending on what department the person is working in .  If I set the report's "Use Specific Printer" to be the same as the default printer no problem. But if I tell the report to use the default printer, it doesn't work. It won't display in print preview. If I go to design view and hit the preview button. The report temporarily goes away and rather  than the Previewed report showing up, it goes right back to design view.  Based on the related thread above, I tried putting in the following code in the report's On Open event using the defailt printer mode:

10 PreviousPrinter = Application.Printer.DeviceName
20 Application.Printer = Application.Printers("HP LaserJet 4000 Series PCL 5 on COOLSERV1")
30 Application.Printer = Application.Printers(PreviousPrinter)

But it failed to work on line 20. Run Time Error 5. Invalid procedure call or argument"
Spent many hours on this so far and stumped.

Have to go to bed now, 12:16 AM EST, but will check this thread first thing in the morning.


Question by:askolits
  • 5
  • 2
  • 2
  • +2
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33518192
Quick thoughts:

1. Are you sure you have the printer name spelled correctly (as it appears on the Network)?
2. Is the printer Online at the time you are trying to Print?

3. Does this problem occur for all databases?, For all users?

4. FWIW, I found no hits on Google for "Application.Printers(PreviousPrinter)"
Are you sure this line is valid?
5. Where are you declaring: "PreviousPrinter"

6. Can you post the Entire code please?


LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33518258
Oh,  ...I think the code in the previous Q will only work in Access 2002 and newer.
You need different code to do the same thing in Access 2000 and older.

Can you also state your Access version please?
LVL 77

Expert Comment

ID: 33518799
The Access version is crucial here in terms of the use of the code in the original post.
But I think we must be careful not to confuse the two issues - the 'printing problem ' and the ' code problem'

The operation of this bit of code is dependent on the Access version. As Jeff said you must have a version later than Access 2000 for this code to 'work'. I use the 'work' here because this code, in its effect, does nothing.  It records the current printer name, sets the default to a different printer and then immediately resets it back to the original name.
So the report will still try to print to the original default printer, not the one assigned by name in the code.

In respect of your posted printing problem, this 'do nothing' code might resolve it, as you say that if you set the report to the same specific printer then everything works ok.  

With regard to the code problem, I have found ACcess to be extremely picky with printer names and I just don't attempt to type them any more.  The problem with the code is almost certainly that Access does not recognise the printer name - not a helpful error message I know but that is my suspicion.

Run this bit of code (assuming Access 2002 or later) and copy from the immediate window and paste the required printer name between the "" in line 20.  Of course, it doesn't actually matter which printer name you choose because it is not used anyway.  

Sub allprts()
Dim prt As Printer
For Each prt In Application.Printers
Debug.Print prt.DeviceName
Next prt

End Sub

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


Author Comment

ID: 33519906
It's Access 2003. I'll try these various solutions. Thanks.

Author Comment

ID: 33520878
OK. Here's the latest.  I changed the name of the printer to "Microsoft XPS Document Writer" in the code above since I know everyone has that printer.  I first tried it at my home office. And it was working.
 I then remote desktoped to a computer on my customer's network and still a problem on that PC. I noticed the MDB was an Access 2000 DB running under Access 2003. I converted the mdb to a 2002-2003 format. Now what happens is when the default printer is "HP LaserJet 4000 Series PCL 5 on Coolserv1" (One of their network printers), I can't even go into design mode of the report. I select the report, select design and nothing happens. Change the default printer to any other printer, no problem. Remember that if I set the report to the Specific  Printer "HP LaserJet 4000 Series PCL 5 on Coolserv1", it works. But not everyone prints to that printer.
I looked at the network  printer permissions and gave everyone rights to all the printer functions but didn;t help. I'll still try a bunch of things on that end.
If anyone has any other ideas, let me know.
LVL 31

Expert Comment

by:Helen Feddema
ID: 33522109
Here is some printer switching code, and also a procedure that lists the printer names as used in code:
Public Function ListPrinters()
   Dim prt As Access.Printer
   For Each prt In Application.Printers
      Debug.Print prt.DeviceName
   Next prt
End Function

Public Sub PrintToSpecificPrinter(strPrinter As String, strReport As String)
'Created by Helen Feddema 12-Feb-2010
'Last modified by Helen Feddema 12-Feb-2010

On Error GoTo ErrorHandler

   Dim prtCurrent As Printer
   Dim prtDefault As Printer
   'Save current default printer
   Set prtDefault = Application.Printer
   Debug.Print "Current default printer: " & prtDefault.DeviceName
   'Select a specific printer as new default printer
   Application.Printer = Printers(strPrinter)
   'Print the report
   DoCmd.OpenReport strReport
   'Set printer back to former default printer
   Application.Printer = prtDefault
   Exit Sub

   MsgBox "Error No: " & Err.Number & "; Description: " & _
   Resume ErrorHandlerExit

End Sub

Open in new window

LVL 77

Expert Comment

ID: 33522128
I'm not competent in the area of remote working but I'm quite aware that in this setup printing is always a problem.

Author Comment

ID: 33525061
Helen thanks for the code, but I can't use a specific printer for the report.
 Update: It's a driver issue. The universal driver provided by HP won't work correctly with this older printer. Haven't been able to find the old driver any where yet on the web, but I did find an old "HP Laser Jet PS" printer in my Add Printer selection box on my personal PC. I then used a program called " Print Migrator Utility"  (for more info see - http://www.emergingtechs.com/posts/how-to-backup-printer-drivers-and-restore-them-on-another-computer/")
This backed up 'ALL' my drivers/printer selections on my PC into a CAB file. I then transferred that file to the remote PC and ran that program to restore all the drivers on the remote PC. Then I was able to add the older printer on the remote PC using 'Add Printer'.  
After that was finished, I made it my default and my Access reporting problem was gone. The only issue is that I only want to copy 1 driver not the many I had on my personal PC. The ultimate solution is finding an older driver.  Anyone know where I can find the older driver for free. "HP Laser Jet 4000 PS".  Not available from HP.
Or anyone know a way to copy just one driver from my PC to another PC?

LVL 14

Expert Comment

ID: 33528465
Google "Driver Max"

Author Comment

ID: 33557885
Everyone: It really looks like a driiver issue. Hopefully will have the solution resolved today. (Mon 8/31/2010)

Accepted Solution

askolits earned 0 total points
ID: 33628483
Well, I installed one of the universal PS drivers from HP and it seems to work. The PLC drivers did not.  It was all very strange but I ended up resolving this issue myself.  Thanks all for your help.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question