View Single Post
 
Old 06-19-2015, 04:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The DATABASE field in your last post is encoded as:
Code:
{ DATABASE \d "{ OS(C:)\test2a\test2a.doc\p/../OS(C:)\Test2a\Test2a.mdb"\s"SELECT [sectionnumber], [description],[borrowerpaid],[borrowerpoc], } FROM QCDPage2areport WHERE [Page2AID=30 \ 1 “1”\b”6”\h” }
Note that all of:
Code:
{ OS(C:)\test2a\test2a.doc\p/../OS(C:)\Test2a\Test2a.mdb"\s"SELECT [sectionnumber], [description],[borrowerpaid],[borrowerpoc], }
is actually another field - all the content is enclosed in a pair of field braces! That will never work, since both your datasource and part of your SELECT statement are inside the field. You may have been led astray by the presence of the {FILENAME \p} field code in the link I posted. That's only there to get the DATABASE field used in that thread to look in whatever folder the document calling it is in - it's not something you'd use if the data source is in another folder.

Your DATABASE field code is mal-formed in other respects, too. It should be something along the lines of:
Code:
{DATABASE \d "C:\\Test2a\\Test2a.mdb" \s "SELECT [sectionnumber], [description],[borrowerpaid], [borrowerpoc] FROM [QCDPage2areport] WHERE [Page2AID]=30" \l "1" \b "6" \h}
The sample document attached to your previous post is even worse - it contains one DATABASE field inside the other, and both contain yet another field within them.

The following excerpt based on a discussion in another forum might help:
Quote:
Suppose you need to create individual merge letters to the members of numerous teams, each with their team number and ID and the letter is to include a list of the individual’s team mates (but without including the individual in the list). The data source is an Excel worksheet with the following field names:
Firstname, Surname, ID, Team
eg:
Alexander, Thompson, 1024, 12
Heather, Thompson, 1025, 12
Michael, Thompson, 1026, 12
Lynette, Andrews, 257, 10
Michael, Richards, 1026, 11
In this case, you could employ a database field, where you:
• use your Excel worksheet as the data source for the merge; and
• insert a DATABASE field into the mailmerge main document to select the records for each individual’s team.
For example, suppose your workbook is “C:\Documents\MyData.xls” and the data are on “Sheet1”. The following set of nested field codes should result in a one-column table listing the name of each participant in the team other than the individual to which the merge record applies:
{DATABASE \d " C:\\Documents\\MyData.xls" \s "SELECT [firstname] & ' ' & [surname] FROM [Sheet1$] WHERE [Team] = {MERGEFIELD Team} AND [ID] <> {MERGEFIELD ID}"}
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote