Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form fields (Word 2002 SP3)

    I have a template with 4 form fields that must be filled out appropriately. I am checking each field with a macro after exiting the field. When I detect an error, I rewrite the original value back into the field and select that field again.
    The macro works as coded but when is finishes, the next field is always selected. It appears to me, that the Tab character entered by the keyboard (which caused the macro to execute) is executed after the macro is finished.
    How can I have the original field stay selected so that the user can correct the data without first back tabbing into the field?
    Thanks for any suggestions

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Form fields (Word 2002 SP3)

    The Exit macro of a Word FormField runs between the time the user asks to leave the field and the time Word proceeds to the next field. There is no "cancel exit" option. So... what to do? Change your approach somewhat and use entry macros to check was the user just did in the last field, and go back if needed. Rough example: <post#=133870>post 133870</post#>.

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields (Word 2002 SP3)

    Two alternatives I've used:

    1. Quick & dirty: SendKeys "+{TAB}" (=Shift Tab) near the end of the ExitMacro jumps back one FormField. But this has it's drawbacks and you should avoid this if possible.

    2. A better approach is to use Application.OnTime :

    Public Sub ExitMacro()
    'Place your code here
    Application.Ontime When:=Now, Name:="GetBack"
    MsgBox "Something is wrong"
    End Sub

    Public Sub "GetBack"
    ActiveDocument.FormFields("YourField").Select
    End Sub

    Application.OnTime fires a timer which causes the call to the specified Sub, in this case GetBack. As soon as a button on the MsgBox is clicked and the first Sub is ended, this Sub is executed and the formfield "YourField" is selected.
    When:=Now works for me in the cases I used it, but maybe you need a little bit of experimenting with the time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •