Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / November 2003

Tip: Looking for answers? Try searching our database.

! Bookmark Referencing from Code !

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wembly - 05 Nov 2003 04:37 GMT
Hi,

I have set up bookmarks and other merged fields in a word
DOT file and want to use code to perform some calculations
to populate certain bookmarked fields.

I was wondering if it was possible to reference a bookmark
from a Word doc, and if so, how it is written?

E.g. The GrossAmount is the bookmark in Word. And the
Datafields "Dollar1/2/3" are referencing "Documents
("filename.DOT").mailmerge.datasource"

GrossAmount = .DataFields("Dollar1").Value _
+ .DataFields("Dollar2").Value _
+ .DataFields("Dollar3").Value

If there is a way to reference bookmarks, which event do I
put this in so that Word knows when to sum it after the
fields have been merged (because prior to merge, there is
no data there for it to sum).

Thanks

Wembly.
Peter Jamieson - 05 Nov 2003 08:36 GMT
I think you may be making this more complicated than it needs to be.

Typically, if you have merge data fields "Dollar1", "Dollar2", "Dollar3",
you should be able to sum them in a nested field that looks (at worst) like

{ ={ MERGEFIELD Dollar1 }+{ MERGEFIELD Dollar2 }+{ MERGEFIELD Dollar3 } }

and avoid any VBA at all. Or, in some cases, you may be able to perform the
calculation in a query in the data source (it depends on the data source).

/If/ you are trying to produce a "grand total" of Dollar1+Dollar2+Dollar3
for all the records in your merge, you should stil be able to do it by
adding the new amounts into a bokmark using e.g.

{ IF { MERGEREC } = 1
"{ SET mytotal 0 }"
"{ SET mytotal { ={ REF mytotal}
+{ MERGEFIELD Dollar1 }
+{ MERGEFIELD Dollar2 }
+{ MERGEFIELD Dollar3 } }" }

But maybe what you are doing requires another approach, in which case please
tell us which
a. version of Word you are using
b. why the above approach will not work

If you are usig Word 2002 or later, there are mailmerge events including an
event that fires for each record in the data source and allows you to modify
the mail merge main document just before the record is merged.

--
Peter Jamieson
MS Word MVP

> Hi,
>
[quoted text clipped - 21 lines]
>
> Wembly.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.