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

Access & Mailmerge Documents

Status
Not open for further replies.

Julesatwork

Technical User
Jan 30, 2002
10
GB
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



 
Here are some suggestions that may help you out:

1. When I have to deal with linked files, I always make my own directory and put all the documents in that one directory. This keeps me in control over where things are and should allow you to remove the paths, since they will all be in one directory (or in the same directory, if you made a subfolder called WORDDOCS for example).

2. If the form you use to launch the merges is set to MODAL, then the user will not be able to multitask while the merge is going on (unless he WANTS to mess it up). This should remove most of the possibilities of the wrong document being processed, since you'll be in control again.

3. Instead of doing a Print, why not do a PrintPreview instead. In this way, the user can double-check the print job and launch the print routine on his/her own. You could also try using the DOCMD to launch the print window within Word, forcing the options screen rather than just sending it to the printer.

Hope this helps.
 
Thanks for the ideas!

1) I already do this but just thought it might be a hassel if the drive letter changed. I am over that one now!

2) Good Idea - I will do that.

3) This one is still a thorn in my side. The application I am building is purely to print inserts which includes barcodes etc to go into product packaging. Users pull up their product through an access form. This is in effect their preview. Now they just want to print e.g 50 Copies to LPT1 - Bin 1 or eg 100 copies to LPT2 Bin1. I can obviously capture those variables but how I apply those variables to word (remember they are not seeing any of this going on which is how they want it!!!) is my big problem. I have been exploring pdevMode and the likes but not sure if this is the right direction. With oApp.ActiveDocument.PrintOut I can specify no of copies but not printer or bin. This has to be as seamless as possible!

Anymore ideas would appreciated!

Thanks

 
Julesatwork:

See if "Docmd.RunCommand acCmdPrint" is what you are looking for. Also, there is a chapter in "Mastering Access 97 Development" (I think that's the name - I don't have it with me) that goes into a lot of detail on how to control printer options. It should be about the same for Access 2K, or even better if you have the 2k version of the book.

K.Hood
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top