Julesatwork
Technical User
Hi There
I am upgrading an Access 2 database to Access 2000. This database currently uses 29 word mailmerge templates which initially I thought I would re-create in Access but they have too much formatting, bullets etc so have decided to stick with the word templates. That's fine she says - just upgrade them to latest version of word and point them to the new datasource (bob's your uncle!)
The Users do not need to view the document - its a simple print function so this is the code I am using for opening 1 template as an example;
Public Sub WordAutomation()
Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim mydoc As Word.Document
'Start a new document in Word
Set oApp = New Word.Application
Set oDoc = oApp.Documents.Open ("C:\test\2UTT.doc"
'Make Word invisible
oApp.Visible = False
'Proceed with mail merge
oDoc.MailMerge.Execute
'Close Main Document
oDoc.Close SaveChanges:=wdDoNotSaveChanges
'Print out new document
oApp.ActiveDocument.PrintOut Background:=False
'Close New Document
oApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Quit Word
oApp.Quit
End Sub
This works seamlessly but I have a few issues with it.
1) What happens if the pathing of the datasource (My Access Application) changes. I don't really want the users to have to update all 29 templates to point to the new location.
2) If I do not hide word and keep a check on what is going on when this routine is running. It obviously opens the Main Document i.e. 2UTT.doc and then the new merged document which is named Forms Letters1.doc. This is the document I need to print and you will see in the code that I am closing the main document and assuming that the one I want to print is the Active document. Whilst I dont need to save the document to print, I would like to specify the document name to print as I am concerned what might happen if another instance of Word is open. How do I get to the name of the merged document. I do not want to assume it will always be Forms Letters1.doc
3) To Print the document I am using oApp.ActiveDocument.PrintOut Background:=False.
I have the added complication as users need to be able to specify printer, No of Copies & Printer Bin. Arrrrggg
If anyone has any better solutions to the above or can point me in the right direction - I would be truley grateful.
Thanks
I am upgrading an Access 2 database to Access 2000. This database currently uses 29 word mailmerge templates which initially I thought I would re-create in Access but they have too much formatting, bullets etc so have decided to stick with the word templates. That's fine she says - just upgrade them to latest version of word and point them to the new datasource (bob's your uncle!)
The Users do not need to view the document - its a simple print function so this is the code I am using for opening 1 template as an example;
Public Sub WordAutomation()
Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim mydoc As Word.Document
'Start a new document in Word
Set oApp = New Word.Application
Set oDoc = oApp.Documents.Open ("C:\test\2UTT.doc"
'Make Word invisible
oApp.Visible = False
'Proceed with mail merge
oDoc.MailMerge.Execute
'Close Main Document
oDoc.Close SaveChanges:=wdDoNotSaveChanges
'Print out new document
oApp.ActiveDocument.PrintOut Background:=False
'Close New Document
oApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Quit Word
oApp.Quit
End Sub
This works seamlessly but I have a few issues with it.
1) What happens if the pathing of the datasource (My Access Application) changes. I don't really want the users to have to update all 29 templates to point to the new location.
2) If I do not hide word and keep a check on what is going on when this routine is running. It obviously opens the Main Document i.e. 2UTT.doc and then the new merged document which is named Forms Letters1.doc. This is the document I need to print and you will see in the code that I am closing the main document and assuming that the one I want to print is the Active document. Whilst I dont need to save the document to print, I would like to specify the document name to print as I am concerned what might happen if another instance of Word is open. How do I get to the name of the merged document. I do not want to assume it will always be Forms Letters1.doc
3) To Print the document I am using oApp.ActiveDocument.PrintOut Background:=False.
I have the added complication as users need to be able to specify printer, No of Copies & Printer Bin. Arrrrggg
If anyone has any better solutions to the above or can point me in the right direction - I would be truley grateful.
Thanks