If then else

C

Cara

Hi~

Is there a way to include more than one merge field in an
if then else statement? What I'd like to do is if my
merge field equals a certain value, then I want to insert
the data from another merge field, not just insert plain
text.

I'm using Office XP Professional.

Thanks for any help/suggestions!!
Cara
 
M

macropod

Hi Cara,

Yes, the syntax might go something like:

{IF{MERGEFIELD Data1}= "" "{MERGEFIELD Data1}" "{MERGEFIELD Data2}"}
or
{IF{MERGEFIELD Data1}= "Test Condition" "{MERGEFIELD Data1}" "{MERGEFIELD
Data2}"}
or
{IF{MERGEFIELD Data1}= "{MERGEFIELD Data2}" "{MERGEFIELD Data3}"
"{MERGEFIELD Data4}"}
etc

Cheers
 
C

Cara

Thanks! It worked great, until I tried to update my "test
condition".

It seems to work only in the first record of my database,
regardless of what variable I put in. (Although when I
merge to a new document, it merges the entire database,
but still no connection to the specified begin date.
Also, when I merge to a new document, it brings up a new
page for each record. I want them all to remain on the
same page, in the individual cells.)

Let me explain what I am trying to use this for, maybe
that will help.

I have two columns "Begin date" and "Info". The begin
date is listed in the date format 9/1/04, 9/2/04 etc.
The "Info" is a listing of program information such as
name, location, staffing, etc.

I am trying to merge these into a Word Document formatted
as a Calendar (template downloaded from MS Online). My
idea is to put a custom "if, then, else" sentence in each
cell of the calendar, with a specific date variable. E.G.
On Sep 1, the code would read: {IF
{MERGEFIELD "Begin_date"}
= "9/1/04" "{MERGEFIELD "Begin_date"}" "{MERGEFIELD "Info"}
"}
My theory was that this should only pull the records that
have a begin date of 9/1/04, and ignore all the others.
Then on 9/2/04, I would replace the date with 9/2/04, and
it would only pull that day, etc.

I think I am just putting something in wrong. Any other
suggestions would be greatly appreciated. Thanks so much!!
Cara
 
D

Doug Robbins

If there is only one record for each date, you probably don't need If then
Else at all. Setting the calendar up as a label type mailmerge document
should cause the data for each date to go into a separate cell. The data
will however need to be sorted into date order.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
C

Cara

Hi~

Thanks so much for all of your help! Unfortunately, there
might be more than one record for each date, and possibly
none at all. E.G. There might be one program on 9/1/04,
none on 9/2/04 and 9/3/04, then four programs on 9/4/04.
That's why I'm trying to figure out the If then Else
sentence. As a last resort, I can just copy and paste my
data out of Excel into my Word calendar, but since the
information will be updated frequently, I was hoping I
could figure out the merge.

If I could just ask for the If then else clarification one
more time, maybe I can get somewhere. I'm also trying to
read up on merge fields on the mvps.org website, to try to
make some sense of the merge sentence. I have been given
a deadline of September 1st to have the calendar up and
running, so I'm getting ready to cut and paste pretty soon.

Again, thanks everyone for their help. Any suggestions
are much appreciated!!

Cara :)
 
D

Doug Robbins

Starting with a Catalog type mailmerge, the following could probably be
modified to do what you want: Depending on your prowess with VBA, copying
and pasting might be easier.

' Macro by Doug Robbins to create multiple items per condition in separate
tables from a directory type mailmerge

Dim source As Document, target As Document, scat As Range, tcat As Range

Dim data As Range, stab As Table, ttab As Table

Dim i As Long, j As Long, k As Long, n As Long

Set source = ActiveDocument

Set target = Documents.Add

Set stab = source.Tables(1)

k = stab.Columns.Count

Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1,
numcolumns:=k - 1)

Set scat = stab.Cell(1, 1).Range

scat.End = scat.End - 1

ttab.Cell(1, 1).Range = scat

j = ttab.Rows.Count

For i = 1 To stab.Rows.Count

Set tcat = ttab.Cell(j, 1).Range

tcat.End = tcat.End - 1

Set scat = stab.Cell(i, 1).Range

scat.End = scat.End - 1

If scat <> tcat Then

ttab.Rows.Add

j = ttab.Rows.Count

ttab.Cell(j, 1).Range = scat

ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True

ttab.Rows.Add

ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False

For n = 2 To k

Set data = stab.Cell(i, n).Range

data.End = data.End - 1

ttab.Cell(ttab.Rows.Count, n - 1).Range = data

Next n

Else

ttab.Rows.Add

For n = 2 To k

Set data = stab.Cell(i, n).Range

data.End = data.End - 1

ttab.Cell(ttab.Rows.Count, n - 1).Range = data

Next n

End If

Next i


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

macropod

Hi Cara,

Depending on what you're doing, perhaps you don't need a mailmerge at all.
Have you tried copying data from the Excel sheet and pasting it into Word
using Edit|Paste Special, and choosing the 'paste link' option? Unless you
need to have different calendars for different people, this should be
sufficient, and will result in the Word document updating whenever the Excel
file is updated.

Cheers
 

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