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 Westi 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

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
 
mapman,

I've only used VBScript to launch applications.

I think that you could use the shell function to launch
wscript.exe with the appropriate parameters.

Just a thought,
Wayne
 
I can't answer your question concerning vbScript, but here's how to change your default printer in Access (Courtesy of "Access 2000 Developer's Handbook Volume 1")

Sub ChangeDefaultPrinterAndPrint()

Dim devs as Devices
Dim dev as Device

'**************************************
'* Set up the collection of devices *
'**************************************

Set devs = New Devices

'*********************************************
'* Store away the current default printer. *
'*********************************************

Set dev = devs.CurrentDevice

'**********************************
'* Change the printer and print *
'**********************************

Set devs.CurrentDevice = devs("HP DeskJet 890C")
Docmd.OpenReport "YourReport"

'**************************************************
'* Set the Default printer back the way it was. *
'* Destroy the Devices object. *
'**************************************************

Set devs.CurrentDevice = dev

Set devs = Nothing
set dev = Nothing

End Sub
 
I tried the code and it fails. I have Access 2000 SP1. I don't have a device as a variable type. Do I need to change my references?

Thanks
 
oops! I had remembered reading about changing the default printer. So when I saw your post I quickly looked up the example, but failed to read the chapter. The author created a class. That is where the Device is declared.

Sorry about that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top