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!

Using VBScript within Access VBA 1

Status
Not open for further replies.

mapman04

IS-IT--Management
Mar 28, 2002
158
US
I have an access app and I want to change the default printer, print a report to it and then reset the default printer. I can call a vbscript to do it and it works fine. Is is possible to just use vbscript from within VBA?

Here's the code I'm trying to run:

Dim WshNetwork as Object

Set WshNetwork = WScript.CreateObject("WScript.Network")

PrinterPath = "\\PrtServer\Printer10"
WshNetwork.SetDefaultPrinter PrinterPath

It returns an "Object Required" error message. I've played with the references but nothing works.

Can this be done?

Thanks,

mapman04
 
Dead easy. You can either create a vbs file and use the code in my FAQ to run it, or you can use this code:

Dim WshNetwork As Object
Dim PrinterPath as String
Set WshNetwork = CreateObject("WScript.Network")

PrinterPath = "\\PrtServer\Printer10"
WshNetwork.SetDefaultPrinter PrinterPath

HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top