Hello all,
I've got an Access select query with the following output:
[TABLE="class: grid, width: 550"]
[TR]
[TD]User[/TD]
[TD]City[/TD]
[TD]Travel[/TD]
[TD]Type[/TD]
[TD]Place[/TD]
[TD]Customer[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]must see[/TD]
[TD]Eiffel Tower[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Louvre Museum[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Orsay Museum[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]business[/TD]
[TD]must see[/TD]
[TD]Eiffel Tower[/TD]
[TD]user1Parisbusiness[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]business[/TD]
[TD]biz[/TD]
[TD]La Defense[/TD]
[TD]user1Parisbusiness[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]must see[/TD]
[TD]National Gallery[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]National Gallery[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Madame Tussauds[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]Rome[/TD]
[TD]business[/TD]
[TD]must see[/TD]
[TD]Colosseum[/TD]
[TD]user2Romebusiness[/TD]
[/TR]
[/TABLE]
I would like to get separated Word documents for each user, city & travel (or Customer), preferably with the bookmarks for each entry in 'Place' column. Of course I don't want to see duplicated items (like National Galery for user2) twice but I managed to avoid them (using grouping in the query). I need the bookmarks because I want VBA code to go to another Word document called e.g. Eiffel Tower and copy its content.
I had similar task previously (but without duplicates and with smaller amount of data) for which I combined Word mail merge IF rule, bookmarks and VBA.
IF rule:
{If {airport}="" "" "airport name"} followed by bookmark 'airport'
A piece of VBA code:
I ended here up with single document for each record from the access and was quite happy with the output.
But I'm struggling now to use it for the query with duplicated entries (no, I can't just delete them). I was working on Mergeseq (added 'Customer' as a key here) but somehow it doesn't see the change in the Travel column. In result I get everything that belongs to user1 in one document (should be in two docs, one for each 'Travel').
Maybe it would work if I put the {MERGEFIELD Customer} right here:
because it counts all the records. I was thinking that maybe there's a way to count only different entries in the Customer column, but I can't find any (would SQL select distinct work here?).
Another thing is that I need to paste description of each 'Place' that applies for a user and travel. Previously I set bookmarks manually but I don't think is feasible here, as I'd need to have as many bookmarks as the records in the 'Place' column for each city and the number will be quite big. Adding a column in Access with the description is not an option as there are some pictures and formatting that would disappear. Have you got any ideas how to do this?
So summing up my long post, I need only two pieces of advice
I've been thinking on that for several days already and can't find any solution other than stated above. Anyone can help?
Thanks in advance!
I've got an Access select query with the following output:
[TABLE="class: grid, width: 550"]
[TR]
[TD]User[/TD]
[TD]City[/TD]
[TD]Travel[/TD]
[TD]Type[/TD]
[TD]Place[/TD]
[TD]Customer[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]must see[/TD]
[TD]Eiffel Tower[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Louvre Museum[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Orsay Museum[/TD]
[TD]user1Parisprivate[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]business[/TD]
[TD]must see[/TD]
[TD]Eiffel Tower[/TD]
[TD]user1Parisbusiness[/TD]
[/TR]
[TR]
[TD]user1[/TD]
[TD]Paris[/TD]
[TD]business[/TD]
[TD]biz[/TD]
[TD]La Defense[/TD]
[TD]user1Parisbusiness[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]must see[/TD]
[TD]National Gallery[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]National Gallery[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]London[/TD]
[TD]private[/TD]
[TD]art[/TD]
[TD]Madame Tussauds[/TD]
[TD]user2Londonprivate[/TD]
[/TR]
[TR]
[TD]user2[/TD]
[TD]Rome[/TD]
[TD]business[/TD]
[TD]must see[/TD]
[TD]Colosseum[/TD]
[TD]user2Romebusiness[/TD]
[/TR]
[/TABLE]
I would like to get separated Word documents for each user, city & travel (or Customer), preferably with the bookmarks for each entry in 'Place' column. Of course I don't want to see duplicated items (like National Galery for user2) twice but I managed to avoid them (using grouping in the query). I need the bookmarks because I want VBA code to go to another Word document called e.g. Eiffel Tower and copy its content.
I had similar task previously (but without duplicates and with smaller amount of data) for which I combined Word mail merge IF rule, bookmarks and VBA.
IF rule:
{If {airport}="" "" "airport name"} followed by bookmark 'airport'
A piece of VBA code:
Code:
For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
ActiveDocument.MailMerge.SuppressBlankLines = True
ActiveDocument.MailMerge.DataSource.ActiveRecord = i
'variables set here
city = ActiveDocument.MailMerge.DataSource.DataFields("city").Value
airport = ActiveDocument.MailMerge.DataSource.DataFields("airport").Value
InputDir = "C:\\location" & "\\" & city
ChangeFileOpenDirectory InputDir
'Set wdApp = GetObject(InputDir, "Word.Application")
Word.Application.Documents.add Template:=InputDir & "\" & city, NewTemplate:=True, Visible:=True 'uses different template for each city
'updates bookmarks
With ActiveDocument
On Error Resume Next
.Bookmarks("airport").Select
Path2 = "C:\\location" & "\\" & city & "\\" & airport name & ".docx"
Selection.Collapse Direction:=WdCollapseDirection.wdCollapseEnd
Selection.InsertFile FileName:=Path2, ConfirmConversions:=False
'mail merge - data from Access query
With .MailMerge
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
.Execute Pause:=False
I ended here up with single document for each record from the access and was quite happy with the output.
But I'm struggling now to use it for the query with duplicated entries (no, I can't just delete them). I was working on Mergeseq (added 'Customer' as a key here) but somehow it doesn't see the change in the Travel column. In result I get everything that belongs to user1 in one document (should be in two docs, one for each 'Travel').
Code:
{IF {MERGESEQ}=1"
{MERGEFIELD user} {MERGEFIELD city} {MERGEFIELD travel}" ""}{SET Customer1 {MERGEFIELD Customer}} {IF {MERGEFIELD Customer1}<>{MERGEFIELD Customer2} "{MERGEFIELD user} {MERGEFIELD city} {MERGEFIELD travel}" "
{MERGEFIELD type} {MERGEFIELD place}"}
{SET Cusomer2 {MERGEFIELD Customer}}
Maybe it would work if I put the {MERGEFIELD Customer} right here:
Code:
{IF {MERGESEQ}=1"{MERGEFIELD Customer}" ""[CODE]
but I don't want it to be visible in the output file.
Obviously, I can't use the VBA code:
[CODE]For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
because it counts all the records. I was thinking that maybe there's a way to count only different entries in the Customer column, but I can't find any (would SQL select distinct work here?).
Another thing is that I need to paste description of each 'Place' that applies for a user and travel. Previously I set bookmarks manually but I don't think is feasible here, as I'd need to have as many bookmarks as the records in the 'Place' column for each city and the number will be quite big. Adding a column in Access with the description is not an option as there are some pictures and formatting that would disappear. Have you got any ideas how to do this?
So summing up my long post, I need only two pieces of advice

- how to make Word to merge records separately for each entry in Customer column
- how to set variable bookmarks for each 'Place' in the documents merged in1.
I've been thinking on that for several days already and can't find any solution other than stated above. Anyone can help?
Thanks in advance!