View Single Post
  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Mail Merge from Access

Try changing

cnn.Execute strSQL

to

cnn.Execute strSQL,,adCmdText+adExecuteNoRecords

I have a suspicion that what happens otherwise is that ADO DB creates a
recordset that has locking implications and is not necessarily cleaned up by
the cnn.Close or perhaps Set cnn = Nothing. (FWIW the Access VBA help says
that a cnn.Close has no effect on the actual connection in this case
anyway - at least I think that's what it says.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"justme0010" wrote in message
...

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