Mail merge from Access 97 to Word 2003 -
09-15-2011
, 07:28 AM
I am trying to merge membership data from my Access 97 database to a
form letter in Word 2003. I have a form which contains members'
personal details. A button on this when clicked opens a dialog box,
allowing me to enter certain specific data (e.g. date the letter will
be despatched which could be days later and date of expiry of new
membership). From a button on the dialog box, I then launch the merge
process with this code:
Private Sub cmdPrintSingleVCard_Click()
Dim objWord As Word.Document, strMergeDoc As String, strSQL As String
On Error GoTo Err_cmdPrintSingleVCard_Click
strMergeDoc = "Q:\Databases\Volunteers\14v0.2gProduction
\VolunteerCardTemplate.doc"
strSQL = "SELECT tblVolunteers.fldContactIDNew,
Format([fldDateVCardIssued],""d mmmm yyyy"") AS IssueDate,
Format([fldDateVCardExpires],""d mmmm yyyy"")"
strSQL = strSQL & " AS ExpiryDate, tblVolunteers.fldCurrent,
tblVolunteers.fldTitle, tblVolunteers.fldInitials,
tblVolunteers.fldForenames, tblVolunteers.fldSurname,
tblVolunteers.fldAddress1Main, "
strSQL = strSQL & " tblVolunteers.fldAddress3Main,
tblVolunteers.fldAddress2Main, tblVolunteers.fldTownMain,
tblVolunteers.fldPostCodeMain, tblVolunteers.fldCountyMain "
strSQL = strSQL & " FROM tblVolunteers WHERE
tblVolunteers.fldContactIDNew =[forms]![frmPrintSingleVCardDialog]!
[txtCurrentID];"
Debug.Print strSQL
Debug.Print strMergeDoc
Set objWord = GetObject(strMergeDoc, "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource Name:="Q:\Databases\Volunteers
\14v0.2gProduction\cltWSBVol.mdb", LinkToSource:=True,
Connection:="QUERY Query1", SQLStatement:=strSQL
objWord.MailMerge.Execute
…error code etc
End Sub
Immediately I get an access error message saying "String is longer
than 255 characters". The Word template opens in the background, of
course with no merged data, just showing the merge fields. I check
the debug.print output and strSQL is fine when pasted into a new query
and the template is being picked up correctly.
Any ideas where I am going wrong? |