Mail Merge from Query into Word 2003

VBA_Googler

New member
Local time
Today, 08:22
Joined
Jan 29, 2013
Messages
2
Hi Guys,

I have this code block


Code:
[FONT=Arial]Private Sub Command55_Click()[/FONT]
 
[FONT=Arial]On Error GoTo Err_Command55_Click[/FONT]
 
[FONT=Arial]   Dim LWordDoc As String[/FONT]
[FONT=Arial]   Dim oApp As Object[/FONT]
 
[FONT=Arial]   'Path to the word document[/FONT]
[FONT=Arial]   LWordDoc = "D:\Template Test.dot"[/FONT]
 
[FONT=Arial]   If Dir(LWordDoc) = "" Then[/FONT]
[FONT=Arial]       MsgBox "Document ain't there!"[/FONT]
[FONT=Arial]       Exit Sub[/FONT]
[FONT=Arial]   Else[/FONT]
[FONT=Arial]           'Create an instance of MS Word[/FONT]
[FONT=Arial]       Set oApp = CreateObject(Class:="Word.Application")[/FONT]
[FONT=Arial]       oApp.Visible = True[/FONT]
 
 
[FONT=Arial]       'Open the Document[/FONT]
[FONT=Arial]       oApp.Documents.Add ("d:\template test.dot")[/FONT]
[FONT=Arial]   End If[/FONT]
 
[FONT=Arial]Exit Sub[/FONT]
 
 
[FONT=Arial]Err_Command55_Click:[/FONT]
[FONT=Arial]   MsgBox Err.Description[/FONT]
[FONT=Arial]   Exit Sub[/FONT]
 
 
[FONT=Arial]End Sub[/FONT]

The template is set up as a mail merge from a query within this database.

The code works essentially, but when the template opens as a new document, there are two issues,

1) It does not merge the fields from the query that it should merge. It opens with the fields like <<Name>>. If i close the DB, it works with no problem.

2) It names the document Document1.doc, when ideally i would like to be able to pass the name of the document in the add string, ie. TestingTemplates.doc. I've googled about, but cant seem to see the option, so i assume i'm using the function in the wrong way.


I hope you guys can help me


VBA_Googler
 
1) It does not merge the fields from the query that it should merge. It opens with the fields like <<Name>>. If i close the DB, it works with no problem.
To answer your first question. In the tool bar at the top of the word document click the toggle ABC not the spell checker and it should change the field name to the merged data .
 
Thanks Ypma, i'll have a look at this!
 

Users who are viewing this thread

Back
Top Bottom