Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unwanted scroll during assignment of value to text field?

Status
Not open for further replies.

MrRedwood

Technical User
Jun 17, 2004
28
US
I've got a text field with the name (i.e., bookmark) of "Duration", which will have the result of the difference between two dates entered somewhere else in my form. When the dates are improperly set up (i.e., the end is before the beginning), I want to empy the duration field. I use:

[tt]Application.Documents(1).FormFields("Duration").Result = ""[/tt]

Question: Why does the screen scroll down until this field is visible? I just want to set it, not jump to it. Is there some way of stopping this behavior?

Supplemental question: is the the most economical way of referring to a field? (I'm not really up to speed on VB's object model).

Thanks for any help!
 
Instead of using vba to clear the 'Duration' field post facto, why not code that test into whatever code/field formula you use to set the 'Duration' field? For example, use logic along the lines of:

IF DATE1 < DATE2 Then
Duration = ""
Else
Duration = DATE1 - DATE2
End If

Cheers
 
I'm not sure how that's different -- the user fields that set the duration field are in a Q&A section on page one; the duration field is in a "results" section on page two. The fields that set the duration field already are variously setting and claring that field, depending on what users enter in -- essentially like you've got.

The problem is that the "OnExit" macro, which is VBA, jump scrolls the user's window down to the Duration field when its value is assigned.

Since I have to be compatible with Macs, I can't use the "other" form fields that have private code snippets, so I don't know of any other way than using OnEntrance and OnExit and using VBA.

The problem isn't just with this Duration field; I only described that one because describing the others would be redundant. But, for instance, I have a set of radio buttons that control the value of a field used later in the same "Results" calculation. The value is placed in a field (it can't just be an off-screen variable, because the user needs to be able to print out the results and have a complete copy of how the results were arrived at), and when the OnExit macors associated with those radio buttons set that field, the window scrolls down to there too.
 
OK,

You should be able to stop the scrolling with:
Application.ScreenUpdating = False
before you update the formfield, and:
Application.ScreenUpdating = True
afterwards.

Alternatively, if you simply set each existing input formfield's properties to 'calculate on exit', you could use an equation/formula field coded as:
Code:
{={SET a{=INT((14-{EndDate \@ M})/12)}}
{SET b{={EndDate \@ yyyy}+4800-a}}
{SET c{={EndDate \@ M}+12*a-3}}
{SET d{EndDate \@ d}}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}
-
{SET a{=INT((14-{StartDate \@ M})/12)}}
{SET b{={StartDate \@ yyyy}+4800-a}}
{SET c{={StartDate \@ M}+12*a-3}}
{SET d{StartDate \@ d}}
{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045} \# ,0;;0}
in place of your 'Duration' formfield to produce the result you're after - no vba required!

Cheers
PS: You can download the above field, fully coded apart from the numeric picture switch at the end, from:
PPS: Using formfields to calculate the result of other formfields (as indicated in your post) is unreliable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top