Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

How to reconnect to network printer using vba

Hello,

A client running an Access 2007 application, reports that the print servers occasionally go down and then come back up.  When it does this, users of the access application have to reconnect to the printers.  Is there a way to do this via vba.  I have a created a table that lists  printers used for each access reports.  Since some of the reports use the same printers, I created a query that returns all the absolute path to all the distinct printers in use by the application.  I then use this query in the code below to loop through each file path.  I'm just trying to figure out how to connect to that printer once I retrieve it's file path.

Public Function ResetPrinters()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim intX As Integer
Dim strPrinterPath As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryPrinters")
Set rst = qdf.OpenRecordset


rst.MoveLast
rst.MoveFirst

For rst = x To rst.RecordCount - 1
    strPrinterPath = rst(x)
    
Next

End Function

Open in new window

Avatar of Juan Velasquez
Juan Velasquez
Flag of United States of America image

ASKER

Hello,

I've done some more research, and I think something like the code below may work. However, how do I check to see if a network printer is already connected.

Public Function ResetPrinters()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim X As Integer
Dim strPrinterPath As String
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qryPrinters")
Set rst = qdf.OpenRecordset


rst.MoveLast
rst.MoveFirst

For X = 0 To rst.RecordCount - 1
    strPrinterPath = rst(X)
    ConnectPrinter (strPrinterPath)
Next

End Function

Private Function ConnectPrinter(strPath As String)

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


 WshNetwork.AddWindowsPrinterConnection strPath



End Function
 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Juan Velasquez
Juan Velasquez
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
Thanks Jim.
Sorry for the delay in posting my solution.