View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
justme0010[_3_] justme0010[_3_] is offline
external usenet poster
 
Posts: 1
Default Mail Merge from Access


Well, here's the code if anyone sees a problem. Like I said before, this
works about 75-80% of the time.

Dim strSQL As String
Dim objWord As Word.Document
Dim ContainingFolder As String 'Full folder path that this database
resides in
Dim cnn As ADODB.Connection

ContainingFolder = CurrentProject.Path
Set cnn = CurrentProject.Connection

'Make sure there are no other records in temp table
cnn.Execute "DELETE * FROM EnvelopeTemp"

'SQLCriteria is a global variable
strSQL = "INSERT INTO EnvelopeTemp (BusinessName, Street, City, State,
Zip, Country) " & _
"SELECT BusinessName, Street, City, State, Zip, Country
" & _
"FROM [tblContactInfo] WHERE " & SQLCriteria

'Fill temp table with addresses
cnn.Execute strSQL

cnn.Close
Set cnn = Nothing

Set objWord = GetObject(ContainingFolder & "\HT System Blank
Template.doc", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True

' Set the mail merge data source as this database
objWord.MailMerge.OpenDataSource _
Name:="", _
ReadOnly:=True, _
Connection:="DSN=MS Access Database;" & _
"DBQ=" & ContainingFolder & "\HT System.mdb", _
SQLStatement:="SELECT * FROM [EnvelopeTemp] ORDER BY [Country] DESC,
[BusinessName] ASC"

'Execute the mail merge.
objWord.MailMerge.Execute

'Close main document, don't save changes
objWord.Close False




--
justme0010