WORD Merge Again

G

Guest

Hi,
I have a form where the user enters a name of a word merge file, begin data,
end date and event type. I have a command button which then process the
following code in the on click event (ingore the line wrap).

Set objWord = GetObject("c:\Mailing List\" & Forms![Report
Menu]![MergeFile] & ".doc", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as Mailing List.

objWord.MailMerge.OpenDataSource _
Name:="c:\Mailing List\Mailing list.mdb", _
LinkToSource:=True, _
Connection:="QUERY MailMergeEvent", _
SQLStatement:="SELECT Last_Name, First_Name, Organization, Address_1,
City, State, Zip FROM [MailMergeEvent]"

The SQL for the query MailMergeEvent is as follows:

SELECT DISTINCTROW [Mailing List].Last_Name, [Mailing List].First_Name,
[Mailing List].Mailing_List_Key, Last([Mailing List].Organization) AS
LastOfOrganization, Last([Mailing List].Address_1) AS LastOfAddress_1,
Last([Mailing List].City) AS LastOfCity, Last([Mailing List].State) AS
LastOfState, Last([Mailing List].Zip) AS LastOfZip
FROM [Mailing List] INNER JOIN [Transaction] ON [Mailing
List].Mailing_List_Key = Transaction.Mailing_List_Key
WHERE (((Transaction.Date) Between [Forms]![Report Menu]![Event_Start_Date]
And [Forms]![Report Menu]![Event_End_Date]) AND
((Transaction.Event)=[Forms]![Report Menu]![Event_Type_Combo]))
GROUP BY [Mailing List].Last_Name, [Mailing List].First_Name, [Mailing
List].Mailing_List_Key;

The merge worked before I added the "GROUP BY" line. I now get a run-time
error 5922 on the objWord.MailMerge.OpenDataSource _........ code

What is a 5922 error or what is wrong with my group by code? If I open the
query by itself it works fine.

Thanks,
 
G

Guest

Thanks for read my question, but I solved the problem.
FYI: When I replaced the field names in the SQLStatement:=" statement with
an * the merge worked fine.

Thanks,
 

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