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!

visual basic mail merge (access and word)

Status
Not open for further replies.

irkle

Programmer
Mar 23, 2003
11
GB
Hi, i hope someone can help me with this problem.. i am running a Mail Merge through my Visual Basic application. When I run the program from the code, it runs the mail merge and opens the Word document with no problems. However, when I compile the executable and run it on other machines, it opens an instance of the Access database used for the Mail Merge. Is there a required dll I am missing? Or am I not thinking along the right lines?
 
Are you using early binding? You establish that through the Project/References menu. In the References dialog select "Microsoft Word x Library". The "x" is the level of Word on your machine. Office 2000 uses "Microsoft Word 9 Object Library".

Next declare an instance of Word. Make it global to the form.

Code:
Private wrdApp As Word.Application

Private Sub cmdDoMailMerge_Click()
   Dim wrdDS As Word.MailMergeDataSource
   ...

   Set wrdApp = New Word.Application
   ...
End Sub

I'm not up on MailMerge, but this will give the gist of approach. Using early binding guarantees that Word will be used. This code will be easier to develop because it of IntelliSense and it will run faste because COM knows exactly what to do.

The caveate is that your users will need the same level of Word on their machines. If they don't you need to use a different set of variable for each level.

A more versital approach is to use late binding.

Code:
 Dim objWd As Object
    
    Set objWd = CreateObject("Word.Application")
    objWd.Visible = True

This will work with any version of Word on your user's machine, assuming that their level of Word supports the objects and methods in your code.
 
I am also experiencing similar problems with MS Access and MS Word Mail Merge - my problems that were similar to yours (i.e. WORD opening DIFFERENT DATABASE INSTANCES) appeared to be corrected by RESETTING the MAIL MERGE DATA SOURCE (in MS WORD) to the proper DB version/NAME. I found that if I was using different DB versions, the WORD DOC would maintain a link to the older version and so I had to RE-ESTABLISH the MAIL MERGE LINK to the PROPER DATABASE VERSION. This fixed the original problem posted here.

ANOTHER BIGGER PROBLEM FOR ME - I am finding that when a document has been opened in XP (using Office XP) - and then I try to bring it BACK to a Win2K envrionment (using Office 2000) - I get a window that pops up in MS WORD when I try to open the MERGED DOCUMENT and point it to an MSACCESS.MDE (i.e. a LOCKED ACCESS DB file) - the Window that pops up wants me to select HEADER RECORD DELIMETERS - with a bunch of special character gibberish in the window below.) - It appears that when attempting to link a DOC file to an MDE file (once it has been already opened in XP) - will corrupt or modify the Header information in the original WORD DOC. Has anybody else seen this type of behavior ?
Any ideas/suggestions for this would be greatly appreciated.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top