How can I do this in Word?

C

Colin Higbie

Here's part of a sentence from a WordPerfect document with explanation. How
can I do the same thing in Word?

....provided IF(FIELD(M/F)=MheELSEsheENDIF is employed by the Company at the
time of issuance thereof and has neither received nor given notice of
Termination subject to Section 11.1 and Section 11.2,
IFNOTBLANK(Contract#)ISO.SUBSTR(FIELD(First Name);1;1)FIELD(Last
Name).FIELD(Vesting Date).SUBSTR(FIELD(Effective
Year);3;2).FIELD(Contract#)ELSEone or more optionsENDIF, which will entitle
FIELD(Last Name) to purchase, in the aggregate, shares of common stock of the
Company...

All the words in all caps except for ISO are merge codes (ISO is just text).

Here's what they do:

1. IF(FIELD(M/F))=MheELSEsheENDIF

There is a data field called M/F, if this is an M, WordPerfect inserts "he"
otherwise it inserts "she"

2. IFNOTBLANK(Contract#)ISO.SUBSTR(FIELD(First Name);1;1)FIELD(Last
Name).FIELD(Vesting Date).SUBSTR(FIELD(Effective
Year);3;2).FIELD(Contract#)ELSEone or more optionsENDIF

The first part checks to see if a data field called Contract# is empty for a
given record, if it is, WordPerfect inserts the text after the ELSE - "one or
more options" however if it's not blank it does more processing to generate
the name of the ISO Agreement, see #3 following

3. (subset of #2) SUBSTR(FIELD(First Name);1;1)FIELD(Last Name).FIELD(Vesting
Date).SUBSTR(FIELD(Effective Year);3;2).FIELD(Contract#)

Extracts the first initial from the data field called First Name, appends the
Last Name, a period, the Vesting Date, another period, the last 2 digits of
the Effective Year, another period, and then the Contract# (e.g.,
ISO.CHigbie.10-30.03.01)


It's #3 that I can't figure out how to do in Word. What's the best way to
accomplish this? I am using just a simple data file created from within the
Merge wizard in Word.

I also perform a search and replace and some calculations at the end of the
merge in WordPerfect, changing a string embedded in the body of the main
document, "~VESTING YEAR~", in multiple places into successively increasing
years based on the Effective Year value (e.g., 2004, 2005, 2006). I can't
figure out how to do that in Word either, but I'll submit another question on
that after I solve this first step (unless someone can tell me how to do based
on this limited explanation).

Thanks,
Colin
 
P

Peter Jamieson

Here's part of a sentence from a WordPerfect document with explanation.
How
can I do the same thing in Word?

It's not at all easy, so the following is likely to come across as
techie-speak.

The IF (FIELD(M/F)) you have here has an equivalent { IF } field in Word,
but you should read up Word Help on fields and switches and learn to use
ctrl-F9 (to insert eh special {} field braces required, and Alt-F9 to switch
between field codes/field results.

There is no equivalent of the SUBSTR function in Word's "field language", so
you have four basic choices, none of which is at all simple:
a. set up a data source that has the substrings you need
b. use a DATABASE field to create the substring you need
c. use Word VBA to do the SUBSTR operation and insert the text you need.
And how to do that depends very much on which version of Word you have - in
Word 2002 and later you can use the Mailmerge events to put the right text
in the mail merge main document before each record is merged, but in Word
2000 and earlier you have to think in terms of putting placeholders in the
text, merging to a new document, then replacing the placeholders with the
text you really want.
d. "roll your own merge" entirely in VBA.

Of these, (a) is probably the simplest of a non-simple bunch as long as you
can either
a. read your text file into a format that lets you manipulate it more
easily (e.g. an Access database) or
b. link to your data source using ODBC (and that can include plain text
files). You can then either use MS Query to create new fields using e.g.

SELECT left(fieldname,1,3) AS `fieldnamefirst3`, * FROM yourdatasource
etc.

or you can use a bit of Word VBA to perform the necessary Query. But even
that has its problems because Word limits the query text to around 255/510
characters and it's very easy to exceed that if you need a lot of different
substrings.

(b) will only be feasible if (a) is feasible, and is probably not worth
describing

(c) is I suppose the way we are expected to do things in Word, at least in
version 2002, but requires you to learn about VBA and the Mailmerge events,
as does (d).

Not sure where that leaves you but we can try to provide more pointers on
(a) if you want.
 
C

Colin Higbie

Thank you! Thank you!

I am using Word 2002 and I am familiar with VBA from other office products
(mostly MS Project actually), but also WordPerfect actually uses MS's VBA
also. I have done quite a bit of document control with VBA in WordPerfect.

I certainly wouldn't call myself an expert, but if that option lets me keep
the control in the document, rather than trying to make the data smarter, I'd
prefer to do it that way. I want to be able to make the document flexible
enough so that if some users enter data a little bit incorrectly
(capitalization, different date formats, etc.), I can actually add code to
correct. Also, the data file is just a little MDB that I created in Word. I
know I can open that in access, but I prefer to have people add data to it via
Word.

How do I use VBA with Mailmerge events?

Thanks,
Colin
 
P

Peter Jamieson

I don't have the time to do the VBA stuff right now but just for the
moment - for some reason I assumed you were using a text file as your data
source, probably since it's the most similar thing to a WP data source in
some ways. But if you're using Access, then the simplest approach is to
create the Access queries that you need and create the necessary columns in
the query using formulae. Then use that query as the data source for the
merge. So for example if your table is called t and you want to extract
characters 2-4 of field f, you can set up a query q which says

SELECT mid(f,2,3) AS `f2to4`, * FROM t

(You'll have to work out how to do this in Access).
 

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