Reply
 
Thread Tools Display Modes
  #1   Report Post  
Viperpurple
 
Posts: n/a
Default IF Statement using multiple Expressions with Bolean

I am trying to create a mail merge using an access data source. The problem
i have is printing a comma seperated list using information stored as
seperate fields with a yes/no answer in the database.

e.g.

Fields:

Bolsover
Chesterfield
Derbyshire Dales
High Peak

List Format:

Bolsover, Chesterfield
OR
Chesterfield, Derbyshire Dales, High Peak

So the main point is that i need to list 'Chesterfield' if the Chesterfield
field is 'True', i have done this but am having real problems adding the ', '
if the value has something preceding it and then missing it out if there
isn't.

Currently using:

{IF {MERGEFIELD "Bolsover"} = "True" "Bolsover" ""}

Tried Using:

{IF {MERGEFIELD "Bolsover"} = "True" "{IF {MERGEFIELD "Chesterfield"} =
"True" ", Chesterfield" "Chesterfield"}" ""}

Sorry for the long post but it was difficult to explain, thanks for reading
and just let me know if you need more info. I really hope you can help, i
think its quite a challenge.

Regards

Adam
  #2   Report Post  
Doug Robbins - Word MVP
 
Posts: n/a
Default

Assuming that the fields are in a table named "Places", if you create an
Access query that contains the following SQL, the desired data will be
displayed in a field named "Result" in the query. Use that query as you data
source and use the Result field to display the data in your mailmerge:

SELECT Places.Bolsover, Places.Chesterfield, Places.[Derbyshire Dales],
Places.[High Peak], -1*([Bolsover]+5*[Chesterfield]+10*[Derbyshire
Dales]+20*[High Peak]) AS Score,
IIf([Score]=1,"Bolsover",IIf([Score]=6,"Bolsover,
Chesterfield",IIf([Score]=11,"Bolsover, DerbyShire
Dales",IIf([Score]=15,"Chesterfield, Derbyshire
Dales",IIf([Score]=16,"Bolsover, Chesterfield, Derbyshire
Dales",IIf([Score]=20,"High Peak",IIf([Score]=21,"Bolsover, High
Peak",IIf([Score]=25,"Chesterfield, High Peak",IIf([Score]=26,"Bolsover,
Chestefield, High Peak",IIf([Score]=30," Derbyshire Dales, High
Peak",IIf([Score]=31,"Bolsover, Derbyshire Dales, High
Peak",IIf([Score]=35,"Chesterfield, Derbyshire Dales, High Peak","Bolsover,
Chesterfield, Derbyshire Dales, High Peak")))))))))))) AS Result
FROM Places;


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Viperpurple" wrote in message
...
I am trying to create a mail merge using an access data source. The

problem
i have is printing a comma seperated list using information stored as
seperate fields with a yes/no answer in the database.

e.g.

Fields:

Bolsover
Chesterfield
Derbyshire Dales
High Peak

List Format:

Bolsover, Chesterfield
OR
Chesterfield, Derbyshire Dales, High Peak

So the main point is that i need to list 'Chesterfield' if the

Chesterfield
field is 'True', i have done this but am having real problems adding the

', '
if the value has something preceding it and then missing it out if there
isn't.

Currently using:

{IF {MERGEFIELD "Bolsover"} = "True" "Bolsover" ""}

Tried Using:

{IF {MERGEFIELD "Bolsover"} = "True" "{IF {MERGEFIELD "Chesterfield"} =
"True" ", Chesterfield" "Chesterfield"}" ""}

Sorry for the long post but it was difficult to explain, thanks for

reading
and just let me know if you need more info. I really hope you can help, i
think its quite a challenge.

Regards

Adam


  #3   Report Post  
Peter Jamieson
 
Posts: n/a
Default

Assuming your "True" comparisons are working (which they should if you are
using the default connection method in Word XP/2003) then the only time you
need to /miss/ a comma is at the very beginning, so try, e.g.

{ SET comma ""
}{ IF { MERGEFIELD "Bolsover" } = "True" "Bolsover{ SET comma ", " }" "" }
}{ IF { MERGEFIELD "Chesterfield" } = "True" "{ REF comma }Chesterfield{ SET
comma ", " }" "" }
}{ IF { MERGEFIELD "Derbyshire Dales" } = "True" "{ REF comma }Derbyshire
Dales{ SET comma ", " }" "" }
}{ IF { MERGEFIELD "High Peak" } = "True" "{ REF comma }High Peak{ SET comma
", " }" "" }
}

where all the {} are the special field braces you can insert using ctrl-F9

Peter Jamieson
"Viperpurple" wrote in message
...
I am trying to create a mail merge using an access data source. The
problem
i have is printing a comma seperated list using information stored as
seperate fields with a yes/no answer in the database.

e.g.

Fields:

Bolsover
Chesterfield
Derbyshire Dales
High Peak

List Format:

Bolsover, Chesterfield
OR
Chesterfield, Derbyshire Dales, High Peak

So the main point is that i need to list 'Chesterfield' if the
Chesterfield
field is 'True', i have done this but am having real problems adding the
', '
if the value has something preceding it and then missing it out if there
isn't.

Currently using:

{IF {MERGEFIELD "Bolsover"} = "True" "Bolsover" ""}

Tried Using:

{IF {MERGEFIELD "Bolsover"} = "True" "{IF {MERGEFIELD "Chesterfield"} =
"True" ", Chesterfield" "Chesterfield"}" ""}

Sorry for the long post but it was difficult to explain, thanks for
reading
and just let me know if you need more info. I really hope you can help, i
think its quite a challenge.

Regards

Adam



  #4   Report Post  
Viperpurpleuk
 
Posts: n/a
Default

Peter, Doug,

Cheers for your help, i have used your solution Peter as it was more suited
and has shown me more about how programming in Word is used.

Thanks

Adam

"Viperpurple" wrote:

I am trying to create a mail merge using an access data source. The problem
i have is printing a comma seperated list using information stored as
seperate fields with a yes/no answer in the database.

e.g.

Fields:

Bolsover
Chesterfield
Derbyshire Dales
High Peak

List Format:

Bolsover, Chesterfield
OR
Chesterfield, Derbyshire Dales, High Peak

So the main point is that i need to list 'Chesterfield' if the Chesterfield
field is 'True', i have done this but am having real problems adding the ', '
if the value has something preceding it and then missing it out if there
isn't.

Currently using:

{IF {MERGEFIELD "Bolsover"} = "True" "Bolsover" ""}

Tried Using:

{IF {MERGEFIELD "Bolsover"} = "True" "{IF {MERGEFIELD "Chesterfield"} =
"True" ", Chesterfield" "Chesterfield"}" ""}

Sorry for the long post but it was difficult to explain, thanks for reading
and just let me know if you need more info. I really hope you can help, i
think its quite a challenge.

Regards

Adam

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Back Arrow when hyperlinking - multiple documents O. Hardin Microsoft Word Help 0 January 13th 05 09:09 PM
Multiple styles in a single paragraph skibikegolf Microsoft Word Help 1 January 5th 05 09:57 AM
How do I get multiple Access records into a single mailmerge lett. Wiley W. Mailmerge 1 December 18th 04 04:47 PM
Using Hyperlinks in Mail Merge IF...THEN...ELSE Statements Mark V Mailmerge 8 November 30th 04 01:31 PM
Need multiple Ifs in Merge Fields Pat Cortez Mailmerge 1 November 30th 04 01:11 AM


All times are GMT +1. The time now is 11:23 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"