Adding query results to text in report (1 Viewer)

rgwood86

Registered User.
Local time
Today, 21:00
Joined
May 5, 2017
Messages
24
Hi all,

Is it possible, just like you would do on a mail merge in Word, to have a report that is predominantly text, but that has inserts which refers to the results of a query.

For example, a query may return the result of a persons name and address, and I would need this to form part of the report not just in an address format, but also in the body of the letter. What would be the best way to do this?

E.G.

[Title] [Forename] [Surname}
[Add 1]
[Add 2]
[Add 3]
[Add 4]
[Add 5]

[Date]

Dear [Title] [Surname],

With reference to your [Account Type] membership with us, we would like to invite you and a guest to a banquet celebrating our 10th Anniversary. The invite is strictly for yourself [Forename] as we are keen to only have account holders at the event.

Don't take the above example literally as I wouldn't be using access for something like this!

Thanks
Rob
 

plog

Banishment Pending
Local time
Today, 15:00
Joined
May 11, 2011
Messages
11,635
Every paragraph that has variable text, you make an entire field and use a query to populate it. So the first paragraph becomes a calculated field in a query:

Paragraph1: "...The invite is strictly for yourself " & [Forename] & " as we are keen..."

Then in your report, kill that big block of text and simply have it show Paragraph1 from the query.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:00
Joined
Feb 19, 2002
Messages
43,203
I don't use the typical Word Mail Merge because it is difficult to control and doesn't give me enough flexibility. Attempting to do substitution in text in Access sort of works but Access doesn't do pagination and nice formatting the way Word does. So I use OLE automation. It is more complicated but ultimately more flexible. I've attached a sample that is as simple as it gets. But the simplicity comes at the expense of flexibility. In my production applications I use mapping tables that give the user the ability to choose fields from queries (I have to have some control of the process) and map them to named bookmarks in word documents. This gives the user control over the documents. He can make new ones and he can add or remove bookmarks provided he updates the mapping table.

But, take a look at the example and see if it will work for you. If your need for merges is minimal and you are OK with having to code new ones, the example will work. Otherwise, you might want to design something more like what I actually use.

The letters are separate from the app due to size limits on attachments to these comments.
 

Attachments

  • SampleWordAutomation160714accdbNoDocs.zip
    102.3 KB · Views: 79
  • SampleLetters.zip
    446.9 KB · Views: 81

Users who are viewing this thread

Top Bottom