Which formfield has the focus

P

Peter Lingo

Hello,
in an template which creates various numbers of formfields (automaticly)
each field has got the same EntryMacro and ExitMacro (named Got_Focus and
Lost_Focus). When the EntryMacro or ExitMacro - event occurs and for example
the Got_Focus routine is called, how can I determine which FormField has got
the focus (and for the Lost_Focus which FormField lost the focus)?

Thanks Peter
 
J

Jay Freedman

Peter said:
Hello,
in an template which creates various numbers of formfields
(automaticly) each field has got the same EntryMacro and ExitMacro
(named Got_Focus and Lost_Focus). When the EntryMacro or ExitMacro -
event occurs and for example the Got_Focus routine is called, how can
I determine which FormField has got the focus (and for the Lost_Focus
which FormField lost the focus)?

Thanks Peter

See http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm.
 
P

Peter Hewett

Hi Peter Lingo

You can use the following code to return the name of the current FormField:

Private Function iwlCurrentFFName() As String
With Selection
If .FormFields.count = 1 Then

' CheckBox or DropDown, with or without a name
iwlCurrentFFName = .FormFields(1).Name

' Only executed if the TextBox has a name
ElseIf .FormFields.count = 0 And .Bookmarks.count > 0 Then
iwlCurrentFFName = .Bookmarks(.Bookmarks.count).Name
End If
End With
End Function

You can use the above function in both the OnEntry and OnExit macros and it will return
the correct FormField Name. Depending upon what you are doing it may in fact be more
useful to return a reference to the current FormField rather than its name.

HTH + Cheers - Peter
 
P

Peter Lingo

Thanks for the answer,
the code works fine nearly, but one question to the behaviour of the events.
Why does the ExitMacro is executed only when loosing the focus by the
tab-key. When a form field has the focus and I click into the text with the
mouse there is no ExitMacro - Events invoked.
That's normal?
Thanks Peter
 
P

Peter Hewett

Hi Peter

No, the OnExit macro should fire however you leave the FormField, i.e.: Tab, Shift+Tab, or
Mouse.

I've just rechecked using Word XP, 2003. I believe this to be consistent with Word 97 and
2000 but I can't double check at this time.

Cheers - Peter

Sorry, yes, that's normal.

HTH + Cheers - Peter
 
P

Peter Lingo

Hi Peter,
The OnExit macro is fired if you click with the mouse to the next formfield,
but if you click on a part of the normal text there is no event fired. The
(little) problem is that you can't avoid that the normal user only click
into the formfields. I've checked this with WrdXP and Wrd2000 and found the
same behaviour.

Regards Peter II
 
P

Peter Hewett

Hi Peter Lingo

Ah, I've got it! You mean you have a document with section breaks and not all of the
sections are protected and when you click in one of the unprotected sections the FormField
you're in does not fire it's OnExit macro.

Yes - yet another one of Words cute idiosyncrasies, makes life a joy what :(

FormField based forms are only robust if they don't contain ActiveX controls and
unprotected sections.

Cheers - Peter


Hi Peter,
The OnExit macro is fired if you click with the mouse to the next formfield,
but if you click on a part of the normal text there is no event fired. The
(little) problem is that you can't avoid that the normal user only click
into the formfields. I've checked this with WrdXP and Wrd2000 and found the
same behaviour.

Regards Peter II

HTH + Cheers - Peter
 

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