×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Changing printers in Access 97 using VBA

Changing printers in Access 97 using VBA

Changing printers in Access 97 using VBA

(OP)
I'm stuck in my Access application for changing the printer for printing reports. I have found code for Access 2000, but this doesn't work in 97. Can anyone guide me how to change my printer in Access 97?

cheers
Steven

RE: Changing printers in Access 97 using VBA

One way that I've done this is to change the default printer to the desired one before printing the report.  I'm curious what code you found for A2K.

The following is some printer code that I've used, and I don't know if it will work in A97, but you're welcome to give it a shot.

One solution that you may want to try, and it's not that difficult, but you do need to include a reference to the Windows Script Host Object Model in your code.

One you setup your combobox, as type ValueList, execute the following from within the form to populate the combobox.

   Dim lStr_PrinterList   As String
   
   lStr_PrinterList = ListAllPrinters
   cboPrinters.RowSource = lStr_PrinterList

And in a module, add the ListAllPrinters function. You skip every other one because the even numbered entries have the Port names, and you don't have to include those.

Public Function ListAllPrinters() As String

   Dim lObj_ScriptControl        As IWshNetwork_Class
   Dim lCol_Printers             As IWshCollection_Class
   Dim lStr_PrinterList          As String
   Dim lInt_Idx                  As Integer
   
   Set lObj_ScriptControl = New IWshNetwork_Class
   Set lCol_Printers = lObj_ScriptControl.EnumPrinterConnections

   lStr_PrinterList = vbNullString
   For lInt_Idx = 1 To lCol_Printers.Count - 1 Step 2
      lStr_PrinterList = lStr_PrinterList & lCol_Printers.Item(lInt_Idx) & ";"
   Next lInt_Idx

   If (Right(lStr_PrinterList, 1) = ";") Then
      lStr_PrinterList = Left(lStr_PrinterList, Len(lStr_PrinterList) - 1)
   End If

   Set lObj_ScriptControl = Nothing
   Set lCol_Printers = Nothing
   
   ListAllPrinters = lStr_PrinterList

End Function

Then in the AfterUpdate event of the combobox add the following:

Private Sub cboPrinters_AfterUpdate()
   SetPrinterAsDefault cboPrinters.Text
End Sub

And in the module, add the SetPrinterAsDefault function

Public Sub SetPrinterAsDefault(rStr_PrinterName As String)

   Dim lObj_ScriptControl        As IWshNetwork_Class
   
   Set lObj_ScriptControl = New IWshNetwork_Class
   lObj_ScriptControl.SetDefaultPrinter rStr_PrinterName
   Set lObj_ScriptControl = Nothing

End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources