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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Word printer from Access

Status
Not open for further replies.

ChrisCalvert

Technical User
Mar 18, 2002
231
US
I am looking for a bit of code to insert in the code below to select a different printer from the default printer listed in the 'Printers' control panel dialog. I am trying to get this to work with
objWord.application.activeprinter
but am having some problems...
Here is the code:

Public Function DoTermMerge()
Dim objWord As Word.Document
Set objWord = GetObject("R:\Termination.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.mailmerge.OpenDataSource _
Name:="R:\Fulfilment.mdb", _
LinkToSource:=True, _
Connection:="TABLE Termination", _
SQLStatement:="SELECT * FROM [Termination]"

objWord.mailmerge.Destination = wdSendToNewDocument
objWord.mailmerge.Execute

'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.

objWord.Application.Options.PrintBackground = False
' hoping for helpful code here
objWord.Application.ActiveDocument.PrintOut
objWord.Application.ActiveDocument.Close (wdDoNotSaveChanges)
objWord.Application.Quit (wdDoNotSaveChanges)
Set objWord = Nothing 'clears object instance from memory
End Function
 
I figured this out. Here is the story. This database in Access grabs an FTP file and imports it. The user needs to print these letters on letterhead, however, this is on a specific printer. No one would normally have this as the default printer. This uses a mail merge in Word controlled from Access. This will save the original deault printer, and change it to one of your choice, and then change it back. So, anyone who is interested in changing printers in Word (From within Word, you would not need the 'objword') here you go:
-------------------------------------------
Public Function DoStopMerge()
Dim objWord As Word.Document
Set objWord = GetObject("R:\StopPayLetter.doc", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True
' Captures the current printer as a string value
Dim PreviousPrinter As String
PreviousPrinter = objWord.Application.ActivePrinter

' Set the mail merge data source
objWord.mailmerge.OpenDataSource _
Name:="R:\Fulfilment.mdb", _
LinkToSource:=True, _
Connection:="TABLE StopLettersData", _
SQLStatement:="SELECT * FROM [StopLettersData]"

objWord.mailmerge.Destination = wdSendToNewDocument
objWord.mailmerge.Execute

'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActivePrinter = "\\al-cpk-fps-001\PRT03099" 'Changes the active printer to the letterhead printer
objWord.Application.ActiveDocument.PrintOut
objWord.Application.ActivePrinter = PreviousPrinter 'returns the printer to the original one
objWord.Application.ActiveDocument.Close (wdDoNotSaveChanges)
objWord.Application.Quit (wdDoNotSaveChanges)


Set objWord = Nothing 'clears object instance from memory
End Function
----------------------------------
Hope this proves useful to someone.
-Chris
 
Thanks Chris :)

I have been wondering how to change the default printer in Word. I am able to print the document I need, but it will print to the default printer. Thanks for your help :)

~ j@ckle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top