Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Jun 2001
    Location
    Kendal, Cumbria, England
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OnExit procedure anomolous behaviour (XP Office 2003)

    I have designed a Word template that has two sections. The first (protected) section contains a table (for formatting) containing three Word forms text boxes. The contents of these are concatenated to give a file name when the user clicks a Save button. To make sure that an invalid file name does not result, there is an OnExit procedure attached to the last text box, which "cleans up" the contents of the text boxes - i.e. it strips out everything except letters, hyphen and apostrophe characters. It also updates bookmark fields in the document header. A copy of the code is attached.
    On my home PC this works fine - after tabbing out of the last text box the insertion point moves to the start of the unprotected section, which is what I want. However on the office system it works fine as long as there are no characters to be stripped out of the text boxes. Depending on how many characters there are it sometimes works OK, but sometimes the insertion point returns to the first text box after tabbing out of the last text box.

    My home PC has office 2003 while the office system uses Office 2000. There are also hardware differences.
    This sounds to me like it might be a timing problem. Does anybody have 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: OnExit procedure anomolous behaviour (XP Offic

    I have Word 2002 and the set-up seems to work the way you want it to (the way it works in Word 2003). Maybe someone with Word 2000 can test your form (a stripped down version) or the attached.

  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: OnExit procedure anomolous behaviour (XP Office 2003)

    As the last line in the Sub UpdateFields(), I would suggest:

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToAbsolute, Count:=2

    You can adjust the Count to any section number required. Alternatively you could use:

    Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext

  4. #4
    Star Lounger
    Join Date
    Jun 2001
    Location
    Kendal, Cumbria, England
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OnExit procedure anomolous behaviour (XP Office 2003)

    Thanks Jan - I put that last line in to try to force the insertion point (although on my home PC it works OK without it). I then paused the procedure just before the Exit Sub (using a MsgBox) to see what happened. The cursor did move to the start of section 2, but after exiting the procedure it immediately went back to the first text box. Wierd.

    George

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

    Re: OnExit procedure anomolous behaviour (XP Office 2003)

    George,

    Are you sure that section 2 isn't protected too? That's the only explanation for this behaviour that I can think of right now.

  6. #6
    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: OnExit procedure anomolous behaviour (XP Offic

    This is a problem with Exit macros on form fields: they can't stop the navigation to the next whatever. You can try to work in a solution in an Entry macro, but I don't think it will be easy in your case.

  7. #7
    Star Lounger
    Join Date
    Jun 2001
    Location
    Kendal, Cumbria, England
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OnExit procedure anomolous behaviour (XP Offic

    Thanks for your help. Jan - the second section of the form is definitely unprotected. There is a workaround for timing problems at http://word.mvps.org/FAQs/TblsFldsFm...ateFFields.htm using an OnTime function that I will try. However I have found another problem - if you navigate between fields using the mouse rather than the tab key, the OnExit procedure doesn't seem to get fired at all. Maybe I'll have to do a big rethink and use a VB form instead of Word form fields to collect the data.

    Thanks again, George

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

    Re: OnExit procedure anomolous behaviour (XP Offic

    I've found and used that mvp.org solution too, in cases that I want to return to the FormFiled that fired the ExitMacro. A normal Selection or GoTo doesn't work in that situation because VBA "remembers" that it has to perform a Tab after the code has finished. OnTime works fine in that situation. In my experience, it's best to set the timer to the smallest amount of time:
    <font face="Georgia">When:=Now + TimeValue("00:00:01")</font face=georgia>
    or even
    <font face="Georgia">When:=Now</font face=georgia>

Posting Permissions

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