Assigning values in a variable to a form field

B

Brian Beck

I have a particular form that goes through occasional revisions and
frequently people submit older versions of the form, rather then the newest
one. I've written a macro to read in the data from all the form fields on
an older form, store that data in variables, open up a new copy of the
latest form template, and then assign the variables to their respective form
fields in the new form. This works great, with a few exceptions:

-I have a Boolean form field that assigns to a variable with no problem.
However, assigning that variable value to the Boolean form field on the new
form is proving difficult. I've tried (where vDTCSameAsSubmitter is the
stored value of the "DTCSameAsSubmitter" form field from the older form)

If vDTCSameAsSubmitter Then
ActiveDocument.FormFields("DTCSameAsSubmitter").Result = True

but that doesn't seem to assign anything to the form field. Similarly if I
try

ActiveDocument.FormFields("DTCSameAsSubmitter").Result =
vDTCSameAsSubmitter

it still seems like nothing gets assigned to the form field. I've inserted
MsgBoxes to show the value of the form field at various times, and it is
constantly "0".

How can I get this variable properly assigned to the form field?


Additionally, there are 2 form fields that contain dates. When there is a
value in the field of the old form, it copies over just fine to the new one.
However, if the field is blank then Word ends up putting the current date
into the form field on the newly created form. I read in the data from the
old form like this:

If ActiveDocument.FormFields("Contact_Date").Result <> "" Then
vContactDate = ActiveDocument.FormFields("Contact_Date").Result
End If

and then assign the variable to the form field on the newly created form
like this:

ActiveDocument.FormFields("Contact_Date").Result = vTEAContactDate

How can I get the macro to simply leave the form field blank on the new form
if there was nothing in that same form field on the old form?

Thanks in advance for any help!

-Brian
 
B

Brian Beck

Why is that AS SOON as I post something I manage to discover the answer on
my own. Somehow the act of asking for help miraculously takes me off on a
tangent that generates results. Go figure.

Anyway, I figured out the answer to at least my first question...my problem
is that instead of my code reading as:

ActiveDocument.FormFields("DTCSameAsSubmitter").Result = vDTCSameAsSubmitter

it should instead read:

ActiveDocument.FormFields("DTCSameAsSubmitter").Checkbox.Value =
vDTCSameAsSubmitter

and then it works just fine.

Now hopefully making THIS post will allow me to come up with an answer for
my second question.

-Brian
 
A

Art H

I must be missing something.

The statement

If ActiveDocument.FormFields("Contact_Date").Result <> "" Then
vContactDate = ActiveDocument.FormFields("Contact_Date").Result
End If

assigns the results of Contact_Date to vContactDate. Then the statement

ActiveDocument.FormFields("Contact_Date").Result = vTEAContactDate

uses the variable vTEAContactDate. Should the expression on the right
of the assignment operator be vContactDate? Further, what might
vContactDate contain if the If expression is false? Might it be better
to perform a similar If for the assignment of the new form or insure
that vContactDate is an empty string before the If executes?

Art
 
B

Brian Beck

You're not missing anything...I simply mistyped the variable name. It
should be vContactDate without the "TEA".

I got around the issue by creating

Dim vEmptyDate As Date

and then simply comparing vContactDate to vEmptyDate. If they were equal,
then nothing is placed in the field, and if they aren't then that means that
something had to have been in the Contact_Date form field and thus it is
copied over onto the new form.

-Brian
 

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