Mailmerge Word problem in VBA with change of location/machine.

Confusion

Registered User.
Local time
Today, 04:42
Joined
Mar 22, 2005
Messages
17
On a database run on a server system the following code was given to me to make a mailmerge word document open and print...

Code:
If Me![TerrorCover] = True Then
DoCmd.SetWarnings False
Dim objword As Word.Document

DoCmd.OpenQuery "MaketblTerror", acNormal
Set objword = GetObject("\\SERVER\Dbs\MailmergeDoc\TerCert.doc", "Word.Document.8")
objword.Application.Visible = True
objword.MailMerge.Destination = wdSendToNewDocument
objword.MailMerge.Execute
objword.Application.Options.PrintBackground = False
objword.Application.ActiveDocument.PrintOut
objword.Application.quit SaveChanges:=wdDoNotSaveChanges
Set objword = Nothing
DoCmd.SetWarnings True
End If

This works fine, but I've been asked to create an exact fully functioning duplicate of the system to run on a machine not connected to the server for training purposes (why?!?!)

so..... the database and mailmerge document now reside in the same folder on this seperate machine, and I changed the code to the following...

Code:
If Me![TerrorCover] = True Then
DoCmd.SetWarnings False
Dim objword As Word.Document

DoCmd.OpenQuery "MaketblTerror", acNormal
Set objword = GetObject("TerCert.doc", "Word.Document.8")
objword.Application.Visible = True
objword.MailMerge.Destination = wdSendToNewDocument
objword.MailMerge.Execute
objword.Application.Options.PrintBackground = False
objword.Application.ActiveDocument.PrintOut
objword.Application.quit SaveChanges:=wdDoNotSaveChanges
Set objword = Nothing
DoCmd.SetWarnings True
End If

But, it doesn't work, nor does anything else I've tried!!!. I get errors re class and file path. Problem is I need to be able to run this in several places so cant tie down to specific paths. Any ideas?!
 
where there is a path to a file in the first example, you need a path to the files in the second or distributed database. my suggestion is to set a string equal to the current app path, and put all your files in the same directory for the training on any pc, and then just use the current path to concatenate with the file name, and the program will work on any machine.

Code:
Dim pstrAppPath As String
Dim dbLocal as DAO.Database

Set dbLocal = CurrentDb()
pstrAppPath = CurrentProject.Path

If Me![TerrorCover] = True Then
DoCmd.SetWarnings False
Dim objword As Word.Document

DoCmd.OpenQuery "MaketblTerror", acNormal
Set objword = GetObject(pstrAppPAth & "TerCert.doc", pstrAppPAth & "Word.Document.8")
objword.Application.Visible = True
objword.MailMerge.Destination = wdSendToNewDocument
objword.MailMerge.Execute
objword.Application.Options.PrintBackground = False
objword.Application.ActiveDocument.PrintOut
objword.Application.quit SaveChanges:=wdDoNotSaveChanges
Set objword = Nothing
DoCmd.SetWarnings True
End If

and make sure you have the DAO 3.5 Library checked

sportsguy

sportsguy
 
Oooops.....

Hi Sportsguy,

Many thanks for that, unfortunately I forgot to mention that this needs to work in Access 97 :o so the currentproject.path bit wont work.

You have however given me the important idea of making the path automatically inserted - Just trying to see if I can come up with some way of using the currentdb.Name path and chopping everything off after the last "\" to give me the directory path! Sort of getting there.... slowly! Any help on this front appreciated!!

Many Thanks!
 

Users who are viewing this thread

Back
Top Bottom