Problem with mail merge

G

Guest

Hi, I am really new to Access and Word (2003)
I want to mail merge but for some reason it is not filling in the << Name >>
all the fields. What I want is to automaticly open the word document (this
works) and to automaticly populate the fields (this is the problem). This is
in the VB function:

Function mergeinfo(docum, textfile, sqlstr)
On Error GoTo Error_AccessToWord
Dim WordDoc As Object
Dim constr As String

On Error Resume Next
Set appWord = GetObject(, "Word.Application")
If Err.number <> 0 Then
MsgBox "Starting Word . . . "

Err.Clear
Set appWord = CreateObject("Word.Application")
End If
Set WordDoc = appWord.Documents.Open(textfile)

'Enable viewing the Word session and its document
appWord.Visible = True

With WordDoc.MailMerge
' constr = "DSN=MS Access 97 " _
& "Database;DBQ=s:\asbdata\asb2\asbdata.mdb;" _
& "FIL=MS Access;"

'.OpenDataSource "s:\asbdata\asb2\asbdata.mdb", , , True, True, , ,
, , , , constr, sqlstr

WordDoc.MailMerge.OpenDataSource
Name:="C:\asb6\datafiles\letter03file.mdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="TABLE tblTempBTO", _
sqlstatement:="SELECT * FROM [tblTempBTO]"

.Destination = wdSendToNewDocument
'Execute the mail merge

WordDoc.MailMerge.Execute
End With
'WordDoc.Close (wdDoNotSaveChanges)
Exit Function


Error_AccessToWord:
AppActivate "Microsoft Access"
Beep
MsgBox "The Following Automation Error has occurred:" & vbCrLf &
Err.Description, vbCritical, "Automation Error!"
Exit Function


End Function


I heard something about a recordsource but I don't know if it is
within the main word document or within VB as a statement and if so then how
would I right this statement.

Also I looked at: "Albert's Super
Easy Word Merge" but this did the samething. It just opens the document
with << field name >> and what I want is for it to auto populate the field
when opening document.

I tried though MS-Word to:

TOOLS: Letters and Mailings: Mailmerge: Next: Next: Browse: Select Datafile
that has data to merge: Select Table: Mailmerge Recipients: Next: More Items:
Select field to insert:.

Then I saved the document and ran the program (no change).


WHAT AM I DOING WRONG!

Thank You for any help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top