Access to Word: Salutation line

G

Guest

Hi,

I would like to automatically insert names from my ACCESS database into a
WORD document. The Word document will be a letter sent out to customers.

Each AutoIDNumber is assigned one or two people's names.

For example, AutoIDNumber=342 could contain Bob Jones
and AutoIDNumber=346 could contain Jane Doe AND Mark Doe. For a particular
record, there are [First Name1], [Last Name1], [First Name2], and [Last
Name2] fields. [First Name2] and [Last Name2] are not always occupied.
[Last Name1] does not necessarily have the same value as [Last Name2],
although it often does.

I know how to insert fields into a Word letter, but I wonder if there is a
way to write code so that when the record contains only a single person's
name, the salutation reads "Dear [First Name1] [Last Name1]" AND
when the record contains two people's names, then the salutation reads "Dear
[First Name1] and [First Name2] [Last Name1]." In the case that [Last Name1]
does not equal [Last Name2], then I would like the salutation to read "Dear
[First Name1] [Last Name1] and [First Name2] [Last Name2]. Is there an
elegant way to do this? I would like to automatically generate letters
according to the above situations. I do not want to manually sort through
records. Does anyone know how to do this?

Thank you, :)
Diana
 
D

Douglas J. Steele

Your best bet would probably to create a query that has a computed field
that determines the salutation. Something like the following should do it:

Salutation: IIf(IsNull([LastName2]), [FirstName1] & " " & [LastName1],
IIf([LastName2] = [LastName1], [FirstName1] & " and " & [FirstName2] & " " &
[LastName1], [FirstName1] & " " & [LastName1] & " and " & [FirstName2] & " "
& [LastName2]))

Use Dear [Salutation] in your letter.
 
G

Guest

Wow--it works perfectly! Thanks!

Douglas J. Steele said:
Your best bet would probably to create a query that has a computed field
that determines the salutation. Something like the following should do it:

Salutation: IIf(IsNull([LastName2]), [FirstName1] & " " & [LastName1],
IIf([LastName2] = [LastName1], [FirstName1] & " and " & [FirstName2] & " " &
[LastName1], [FirstName1] & " " & [LastName1] & " and " & [FirstName2] & " "
& [LastName2]))

Use Dear [Salutation] in your letter.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



DianaS said:
Hi,

I would like to automatically insert names from my ACCESS database into a
WORD document. The Word document will be a letter sent out to customers.

Each AutoIDNumber is assigned one or two people's names.

For example, AutoIDNumber=342 could contain Bob Jones
and AutoIDNumber=346 could contain Jane Doe AND Mark Doe. For a
particular
record, there are [First Name1], [Last Name1], [First Name2], and [Last
Name2] fields. [First Name2] and [Last Name2] are not always occupied.
[Last Name1] does not necessarily have the same value as [Last Name2],
although it often does.

I know how to insert fields into a Word letter, but I wonder if there is a
way to write code so that when the record contains only a single person's
name, the salutation reads "Dear [First Name1] [Last Name1]" AND
when the record contains two people's names, then the salutation reads
"Dear
[First Name1] and [First Name2] [Last Name1]." In the case that [Last
Name1]
does not equal [Last Name2], then I would like the salutation to read
"Dear
[First Name1] [Last Name1] and [First Name2] [Last Name2]. Is there an
elegant way to do this? I would like to automatically generate letters
according to the above situations. I do not want to manually sort through
records. Does anyone know how to do this?

Thank you, :)
Diana
 

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