I have recently been thusted in to the position of fixing the errors in our mail merge document. THe problem is this. It was originally designed using word 97/200 (don't know which). The office now uses 2002 (XP). With this change came an onslought of issues. I have resolved most of the but not this one. The word macro opens an excel files to create a series of form letters based on conditions. If the entry donated x amount use this letter, if the entry is for a staff member use this letter, etc. This is all done by using query string in the
VB code. When I run the script, it generates an error message "Word could not merge the main document with the data source because the data records were empty or no data records matched your query options." IF the user hits ok, the program resumes. This message will pop up at least twice for all 6 documents we have. At the end of the macro, it completes and all is fine. The problem is that the macro can take ~5 minutes to run. If the user has to stay and keep clicking "ok" they get pissed and call me. If I rem out the query statement, the merge works, but it generates the letters for every entry without disgression. I have determined that the cause fo the error is a the query line the first of which is as follows...
ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM K:\MergeData.xls WHERE ((Gifts_1_Amount = 0) AND (Subcategory <> 'Staff') AND (Gifts_1_Giftcode <> 'SC') )"
the K drive is the location to the shared files. Stargely enough, I tried using MSQuery to generate a query statement, but it said the table was a hidden system one. Could that have something to do with it? If so, how do I change it. I should also tell you that the excel files is generated by the macro too. The original data source is a dat file export from our Member tracking software.
I am not a expert in
VB (more of a network guru) but I am sure the error is incorrect syntax in the query. OH, by the way, there is a call before the query that opens the excel file for use...
With ActiveDocument.MailMerge
.OpenDataSource Name:="K:\MergeData.xls", _
SubType:=wdMergeSubTypeWord2000
Once the database has been opened by the first call, do I have to reference if from that point using the full path to the file? Seems kinda strange. I really appreciate any help you guys can give me. I have inherited this code and am wading through the waters of source code and documentation.
Bill