Change Data in a Word form Control.

R

Richard Gutery

I have a VB macro that displays a dialog box (very straight forward).

I want to be able to change a Word document Form Field based on some data
entered into the VB form.

All the MS online help suggests the below code will do the trick (the quotes
are for outline purposes only and are not part of my code):

"ActiveDocument.FormFields("Faxto").Result = txtFaxNo"

All I get is "runtime error 5941".

Any help would be greatly appreciated.

Thanls.

RG
 
C

Cindy M -WordMVP-

Hi Richard,
I have a VB macro that displays a dialog box (very straight forward).

I want to be able to change a Word document Form Field based on some data
entered into the VB form.

All the MS online help suggests the below code will do the trick (the quotes
are for outline purposes only and are not part of my code):

"ActiveDocument.FormFields("Faxto").Result = txtFaxNo"

All I get is "runtime error 5941".
Do you get any error text on that, that could help us narrow things down a bit?
Right off-hand:
- You'd need to take away the opening and closing quotes
- You probably shouldn't be using ActiveDocument, but an object variable
already assigned to the document object you're working with
- Is "Faxto" a text box form field? And is that really the field's name?
- txtFaxNo should be fully qualified

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
R

Richard Gutery

Hi Cindy, thanks for the reply. To address your points:
1) The opening and closing quotes (as indicated in my post) are for OUTLINE
purposes only,
2) I'm not sure what you are meaning by 'Object Variable'. I understand what
they are and how to use them, but how would I create an Object Variable to
referrence an Active Document?,
3) FaxTo is a "Merge Field" and it is the name,
4) txtFaxNo is actually qualified now.

Finally, I have no Text Description of the error. Just the error message.

For the interim, I developed a VB application that serves the purpose and
works, with a few minor issues.

We really would like to have this work entirely in Word, so any further help
would be nice. If you like, I can send you the code (or the entire .DOT
file).

Also, I have charged out and purchased several books on 'Word Basic', so
maybe they may help.

Thanks for the response, it is appreciated.

RG
 
C

Cindy M -WordMVP-

Hi Richard,
Also, I have charged out and purchased several books on 'Word Basic', so
maybe they may help.
any literature for the WordBasic language would be woefully out-of-date. The
last version of Word in which that was native was Word 95! Some of the lists
are still useful knowing the data type of a dialog box control (when still
supported), but that's pretty much the extent of it.
2) I'm not sure what you are meaning by 'Object Variable'. I understand what
they are and how to use them, but how would I create an Object Variable to
referrence an Active Document?,
If you're opening or creating a new document, set the object variable then:
Set doc = Documents.Open("FileName")
Set doc = Documents.Add

If you're having to work with a document the user has opened, then
Set doc = ActiveDocument

The problem with just using ActiveDocument is that the "focus" in Word might
change so that, suddenly, the document you expect is no longer the Active
one.
3) FaxTo is a "Merge Field" and it is the name,
Well, if it's a MERGE FIELD, then using the FormFields collection certainly
won't work. The two are not the same thing. Are you using form fields or
merge fields in the document?
For the interim, I developed a VB application that serves the purpose and
works, with a few minor issues.
Knowing which approach is functioning might help track down the problem.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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