Mail Merge Problem

A

Amour

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



WHAT AM I DOING WRONG!

Thank You for any help!
 
P

pietlinden

How did you insert the chevrons? If you did it manually, that's the
problem. You have to insert the fields from the database. Once you
specify the recordsource, you should have a dropdown in the top left
of the toolbars where you can select the fields you want in your merge
document. Of course, you could do teh easy thing and get Albert's
"Super Easy Word Merge" from his website...
 
A

Amour

Hi, and thank you for your help.

OK now I am really confused. What do you mean recordsource and do you mean
within the main word document or within VB as a statement and if so then how
would I right this statement. Also I don't know the term: "Albert's Super
Easy Word Merge" where can I find it?

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).

Please help and thank you!
 
A

Amour

Hi, again (I guess U come in late) and thank U for helping.

I looked up: "Super Easy Word Merge" and found it to be doing the samething
as my VB Code. It opens the document, but with << >> instead of a name. So
what is going on, do U (in 2003 word) have to manaully run mail merge?

Thank You for help....
 
P

pietlinden

Hi, again (I guess U come in late) and thank U for helping.

I looked up: "Super Easy Word Merge" and found it to be doing the samething
as my VB Code. It opens the document, but with << >> instead of a name. So
what is going on, do U (in 2003 word) have to manaully run mail merge?

Thank You for help....

you have to read the instructions on Albert's code. If I remember
right, it's documented right on the website.
 
A

Amour

Thank You again...

Well I went line by line on this and at the end it says:

Note that when you merge with the template, the result has NO merge fields
in it. It is a nice standalone document that you can print, email, or do
whatever you want with (there is no connection to the access file that
remains).


So what is this saying? It sounds like by the line: "the result has NO
merge fields in it" it will not automaticly populate. I want it to
automaticly populate when the VB code opens the word document.

I don't want to have to do:

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:.


Each time I run this VB code:

So far: "Super Easy Word Merge" does exactly what my VB is doing. I want
more I want it to write the fields witnin the table to word automaticly when
opening (not just << field name >>.

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