linking variables to field codes

G

Gem_man

Can anyone advise on this one please.

I have a series of string and numerical variables produced
as a result of user input to comboboxes and mathmatical
calculations within the code.

I want these variables to be made available for insertion
in specific places in a word doc taken from a word
template. I intend for the user to be able alter the exact
placement of these results by moving the fields original
template (makes sense so far?).

I am thinking that field codes would be the way to go
(only an assumption) as these can be moved by the user in
the basic template.

My problem is how do I link these variables to field codes?

Is this the best way of doing it?

And since I may end up using the idea in VB6 is there a
better way that will allow this to happen in VB6?

I really would appreciate any assistance and suggestions.
I cannot seem to find any info on this in the help files.
I suspect that the things I am thinking of are not called
field codes.

Thanks

Gem_man
 
P

Peter Hewett

Hi Gem_man

I'm presuming you are using a UserForm for data entry, hence the ComboBoxes?

If this is the case you can have the UserForm store the data in Document Variables, then
in your Template you can refer to the document variable you require by inserting a
DocVariable Field. The only problem is if the user inadvertently deletes the Field from
the template. But you could add some extra code that checks that there are Fields in the
template that refer to all of the necessary Document Variables.

Normally document stuffing is done by inserting bookmarks in the Template and then
creating a new document from the template and inserting the required text into the
bookmarked locations.

Give both methods a try and see which one you prefer as there are other issues that can
come into play with both techniques.

HTH + Cheers - Peter
 
G

Gem_man

Hi Peter,

Great answer thank you.

I like the sound of the document variable option best. I
think this will meet my needs better.

Yes, the controls are in a userform.

The help file is still not giving me any info on how to
link the data in the vba code to the document variable.

Can you give me a hint as to how this is done, then I can
start experimenting. Failing that does anyone know of a
site that has some examples I could play with.

Many thanks

Gem_man
-----Original Message-----
Hi Gem_man

I'm presuming you are using a UserForm for data entry, hence the ComboBoxes?

If this is the case you can have the UserForm store the
data in Document Variables, then
in your Template you can refer to the document variable you require by inserting a
DocVariable Field. The only problem is if the user
inadvertently deletes the Field from
the template. But you could add some extra code that
checks that there are Fields in the
template that refer to all of the necessary Document Variables.

Normally document stuffing is done by inserting bookmarks in the Template and then
creating a new document from the template and inserting the required text into the
bookmarked locations.

Give both methods a try and see which one you prefer as
there are other issues that can
 
P

Peter Hewett

Hi Gem_man

The point of using a DocVariable Field is that you don't need code to insert it in the
document, only code to update the DocVar value. Here's how to create/update a Document
Variable:

ActiveDocument.Variables("Test").Value = "My value"

It assumes you're using the active document but if your using Automation from VB it would
be better to create a specific Word.Document object. Test is the name of the Document
variable and "My value" its value.

In the Template to insert a DocVariable field you move the insertion point to where you
want the Field and then either:

1. Use Words menu: Insert>Field>DocVariable>the doc variables name; or
2. Press Ctrl+F9 to insert a field "{ }", move the cursor within the Field and then type
"DocVariable Test", it should look like this: { DocVariable Test }. Now press F9 to
toggle the field from "View field codes" to "View field results".

Also check out:

This is the Word MVP website, and there's heaps of useful stuff there:
http://word.mvps.org/

Post again if your still stuck.

HTH + Cheers - Peter
 
G

Gem_man

Peter,

Perfect. I get it now. Many, many thanks.

Gem-man
-----Original Message-----
Hi Gem_man

The point of using a DocVariable Field is that you don't need code to insert it in the
document, only code to update the DocVar value. Here's
how to create/update a Document
Variable:

ActiveDocument.Variables("Test").Value = "My value"

It assumes you're using the active document but if your
using Automation from VB it would
be better to create a specific Word.Document object.
Test is the name of the Document
variable and "My value" its value.

In the Template to insert a DocVariable field you move
the insertion point to where you
want the Field and then either:

1. Use Words menu: Insert>Field>DocVariable>the doc variables name; or
2. Press Ctrl+F9 to insert a field "{ }", move the
cursor within the Field and then type
"DocVariable Test", it should look like this: {
DocVariable Test }. Now press F9 to
 

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