Get value from Field

N

Nigel

I am trying to get a value from a field on a form but no matter what I do the
value returned is always 70, here is the code I am using

Sub SR()


Dim Message, Title, vusername
Message = "Is this Member Competing in Stationary Roping (Y or N)" ' Set
prompt.
Title = "Stationary Roping" ' Set title.
' Set default.
' Display message, title, and default value.
vSR = InputBox(Message, Title)
ActiveDocument.FormFields("Sr").Result = vSR
MsgBox ActiveDocument.FormFields("Level")
Exit Sub
End Sub

The message box is just a msg validating what value I am getting because I
am going to do some other stuff after that, where am I going wrong in getting
the value from a field

thanks
 
D

Dave Lett

Hi Nigel,

This might be too simple, but you're setting the value of the "Sr" field but
showing the value of the "Level" field. Perhaps you should change the line:

MsgBox ActiveDocument.FormFields("Level")

to

MsgBox ActiveDocument.FormFields("Sr")

HTH,
Dave
 
N

Nigel

Its actually looking back to another field on the form and what I want to do
is check the value in the level field and if it is greater than 4 go to one
field and if its less than 4 go to another field, I can do all that easy
enough but I just can't get the value from the level field
 
D

Dave Lett

Hi Nigel,

The default value of the Level field is probably "70." However, the current
result of the Level field might be something else entirely. To get the
current result, use

MsgBox ActiveDocument.FormFields("Level").Result

HTH,
Dave
 
D

Dave Lett

Hi Nigel,

You can test this with the following:

ActiveDocument.FormFields("Level").Result = 44

MsgBox ActiveDocument.FormFields("Level")
MsgBox ActiveDocument.FormFields("Level").Result

HTH,
Dave
 
N

Nigel

Thanks Dave that worked,

Can I ask another question

I have some calculations ont he form and I want to nadd the totals together
so I am using the follwoing

ActiveDocument.FormFields("ATOTAL").Result =
ActiveDocument.FormFields("A1Ext").Result +
(ActiveDocument.FormFields("A2Ext").Result) +
(ActiveDocument.FormFields("A3Ext").Result) +
(ActiveDocument.FormFields("A4Ext").Result) +
(ActiveDocument.FormFields("A6Ext").Result)

if I use a msg box on each of those fields I will get the values in the
field ie 35.00 20.00 etc

but when I use the above statment it it treating the + as concat and joins
them together, the fields on the form are numbers, is ther an easy way to add
2 or more fields together

Thanks
 
T

Tony Jollans

Actually the 70 is the value of the default property of the FormField. When
you reference the FormField with other than a Set statement you are asking
for the default property, which in this case is Type - wdFieldFormtextInput
(value 70). If you want the value as seen on screen (the Result) you should
explicitly say so, as per Dave's suggestion.
 
D

Dave Lett

Hi Nigel,

You can try specifying a data type:

CLong (ActiveDocument.FormFields("A1Ext").Result)

HTH,
Dave
 

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