Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Inexplicible FormField.Result comparison

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zSplash - 07 Jun 2005 00:25 GMT
Here is my code, which is running as I exit a formfield (neither "tbxF5" or
"tbxM5"):
   MsgBox ActiveDocument.FormFields("tbxF5").Result
   MsgBox ActiveDocument.FormFields("tbxM5").Result
   If ActiveDocument.FormFields("tbxF5").Result >
ActiveDocument.FormFields("tbxM5").Result Then
       ActiveDocument.FormFields("tbx6FDiff").Result = Diff
       ActiveDocument.FormFields("tbx6MDiff").Result = ""
   Else
       ActiveDocument.FormFields("tbx6MDiff").Result = Diff
       ActiveDocument.FormFields("tbx6FDiff").Result = ""
   End If

When the msgboxes pop up, it's clear that "tbxF5" is smaller than "tbxM5",
yet the code consistently chooses the first possiblity.  I have defined both
"tbxF5" and "tbxM5" formats to be number: #,##0.00.

Would someone please explain this to me?

TIA
Jay Freedman - 07 Jun 2005 00:43 GMT
It's a little hard to say without seeing the values you're comparing,
but I'll guess that it's saying something equivalent to 11 < 2. The
problem is that even though the field formats are defined as "number",
the values themselves are strings -- they're strings that must contain
only digits, periods, and commas, but still strings. Therefore VBA is
comparing them as strings, not numbers.

You need to compare the number equivalents of the strings to get a
reliable result. Do something like this:

  Dim numF5 As Single, numM5 As Single
  numF5 = CSng(ActiveDocument.FormFields("tbxF5").Result)
  numM5 = CSng(ActiveDocument.FormFields("tbxM5").Result)
  If numF5 > numM5 Then
    ...

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Here is my code, which is running as I exit a formfield (neither "tbxF5" or
>"tbxM5"):
[quoted text clipped - 16 lines]
>
>TIA
zSplash - 07 Jun 2005 17:28 GMT
Works fine now, with your help.  Thanks, Jay.

st.

> It's a little hard to say without seeing the values you're comparing,
> but I'll guess that it's saying something equivalent to 11 < 2. The
[quoted text clipped - 37 lines]
> >
> >TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.