Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
TechScribe TechScribe is offline
external usenet poster
 
Posts: 5
Default Calling a VBA function in MS Word

I have an existing document that I must fill in with information from an
Access database.

One field has so many IF ... THEN ... ELSE statements, MergeFields, and
Bookmarks that I can no longer read it.

So I opened the VBA Editor and created a function to replace it all. That
part was easy, taking five minutes because I stopped to pour another cup of
tea.

I created the function yesterday morning. I still cannot figure out how to
call that function to fill in the field on the document as though it were
calling a Merge Field.

Thank you for your time.
TechScribe
--
Write well, and do good works.
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Calling a VBA function in MS Word

There is no built-in mechanism using fields to insert the result of a /Word/
VBA macro into a document during a merge.

Possible approaches to this include:
a. you write the function in Access VBA, include it in an Access query,
then use that query as your datasource, connecting to it using DDE (which
lets you use the Access VBA function but has other drawbacks, e.g. won't let
Unicode data through)
b. you write the function as part of an Access query and use that as the
data source with whatever connection method you like.
c. you use Word MailMerge Events and VBA to set the value of a Document
Variable to the result of your function, for each record merged (more or
less). use a { DOCVARIABLE } field to get the data into Word
d. you use a Word VBA macro to perform one merge per record and do much the
same as (c)
e. similar to (b) but you use a DATABASE field to insert the result - only
really workable these days if the result is a number or a date.

If the function is sufficiently simple, only relies on other data in your
data source and standard Jet SQL information functions such as date, and you
are in a position to modify your Access database, (b) is probably the best
approach. (a) would not be bad - again if the data all comes from Access -
if you are already connecting using DDE. (c) is the "official" way to do VBA
during merges, but (d) is probably simpler where it is feasible. You can
find examples of most of these approaches by searching this group in Google
Groups (e.g. look for Peter jamieson activerecord for (d).

Peter Jamieson

"TechScribe" wrote in message
...
I have an existing document that I must fill in with information from an
Access database.

One field has so many IF ... THEN ... ELSE statements, MergeFields, and
Bookmarks that I can no longer read it.

So I opened the VBA Editor and created a function to replace it all. That
part was easy, taking five minutes because I stopped to pour another cup
of
tea.

I created the function yesterday morning. I still cannot figure out how to
call that function to fill in the field on the document as though it were
calling a Merge Field.

Thank you for your time.
TechScribe
--
Write well, and do good works.



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
fax with calling card Fax New Users 1 August 22nd 06 08:39 PM
Calling a sub with argument in VBA Pyth007 Microsoft Word Help 0 July 22nd 05 08:29 PM
Calling all Wizards! stephanie Microsoft Word Help 6 June 2nd 05 07:26 AM
Calling out comments Opinicus Microsoft Word Help 4 February 24th 05 04:40 PM
How do I send a fax using a calling card? mocha4me2 Mailmerge 1 February 10th 05 06:21 AM


All times are GMT +1. The time now is 08:43 PM.

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"