Craziness!

Rob Sang

Registered User.
Local time
Today, 10:02
Joined
Jul 12, 2003
Messages
12
Okay, so I've written this code to launch a mail merge from an Access form. It works fine to merge ALL the records in the database, but if I change the SQL line to read:

SQLStatement:="SELECT * FROM [Customers] WHERE [MailingListID] = '" & MailingListID & "'"

random craziness ensues, with windows popping up everywhere. My intention is to merge only the record I have just entered into the form (MailingListID being the primary key).

Anybody know what I'm doing wrong?

Code below:


Private Sub merge_Click()
On Error GoTo Err_merge_Click

Dim objWord As Object

Set objWord = GetObject("C:\WINDOWS\DESKTOP\newdb\merge2.doc", "Word.Document")
objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
Name:="C:\WINDOWS\DESKTOP\newdb\newdb.mdb", _
LinkToSource:=True, _
Connection:="TABLE Customers", _
SQLStatement:="SELECT * FROM [Customers]"
' Execute the mail merge.
objWord.MailMerge.Execute

Exit_merge_Click:
Exit Sub
 
Try this

SQLStatement:="SELECT * FROM [Customers] WHERE [MailingListID] = " & Forms!FormName!MailingListID
 
Thanks, that's sorted it out!
 

Users who are viewing this thread

Back
Top Bottom