Link to home
Start Free TrialLog in
Avatar of rezasaha
rezasaha

asked on

I am using Application.Printers(MyPrinterName), but when it gets to that line, MS-Access is crashing!

I am using a VBA code in MS-Access to change the printer dynamicaly.
I have the following code:

MyPrinter = "HP Laser Jet"
APPLICATION.Printer=APPLICATION.Printers (MyPrinter)

But MS-Access is crashing when it gets to the second line  "APPLICATION.Printer=APPLICATION.Printers (MyPrinter)"

In the refrences I have selected:
Visual Basic for Applications
Microsoft Access 11.0 Object Library
Microsoft Forms 2.0 Object Library
Microsoft DAO 3.6 Object Library
Microsoft Windows Common Controls-2 6.0 (SP4)
Microsoft ActiveX Data Objects 2.7 Library
Microsoft Visual Basic for Applications Extensibilty 5.3
OLE Automation

The funny part is that the code works on some PCs!

No the other problem is that as soon as I type Application, it changes it to all CAPS  (APPLICATION)

Any clue will be appreciated.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Do you actually have a printer named EXACTLY like that? If not, you'll have troubles and since you say this works on some machines but not others, this is where I'd look.

You can iterate  the Printers collection to determine exactly what Printers are available:

Dim prt As Printer

For Each prt In Application.Printers
  Debug.Print prt.DeviceName
Next
Avatar of rezasaha
rezasaha

ASKER

I used this code, MS-ACCESS crashed again! it did not run this code either.

It changes the Application to all CAPS, I have feeling that some thing is not set up right in this file, but I cannot figure out what?

ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The problem happened to be the PC itself, however, thank you for the hint and time to respond.
What exactly was the problem on the PC?