Results 1 to 12 of 12
  1. #1
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Focus problem? (Win XP / Word XP/2003)

    I have several templates made in Win 98 / Word 97 using Forms and code to handle them.
    Now I'm testing these templates in Win XP / Word XP and Word 2003. There's one particular issue that I cannot understand and address: when loaded and made visible yo the user (frmName.Show) the form appears to have the focus, but the first click on an object on the form seems not be recognized, so a second click is necessary. This goes for any form. This is somewhat annoying, to say the least.
    Anyone knows what causes this behavior? Thanks.

    JanB

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Focus problem? (Win XP / Word XP/2003)

    I don't see this behavior in Word 2002 SP-2 on Windows XP (Pro or Home, SP-1). The first control in the tab order gets the focus and a single click is sufficient to set focus to another control. Do you have code in the Initialize event of the form that might influence this, or code in the On Mouse Down / Move / Up events?

  3. #3
    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: Focus problem? (Win XP / Word XP/2003)

    I haven't seen that with UserForms (I don't do a lot of them), but I have seen it with the application window itself. This goes away if I restart the application (I think, or did I log off/log on again?). Word 2002 also leaves an outline where the Find/Replace dialog overlapped windows outside the Word window. Basically, there's a bit of slop in the interface and you might have run into one of those little problems. Try closing Word and starting it again and see if the problem goes away as mysteriously as it started.

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

    Re: Focus problem? (Win XP / Word XP/2003)

    The user-templates don't contain any code or form. All forms and code are in a seperate code-template sitting in the Word Startup directory, so they can be used in any template throughout the session of Word. There are 9 forms, 7 of which are called by a Sub activated by a click on a button in a commandbar and 2 are called by a FormField ExitMacro. The forms contain radiobuttons and/or textboxes for user choices/input. Most of them just have a OK-button and no Cancel-button to force the user input. For that reason they contain a Private Sub UserForm_QueryClose to prevent closing the form with the X-button.
    Usually the form is first Loaded, changes to radiobuttons and textboxes are made based on former input or standards, then the form is activated (frmName.Show). The form-code usually is limited to Private Sub cmdOK_Click and, if appropriate, Private Sub cmdCancel_Click, both hiding the form. In 2 cases there is a Private Sub Userform_Initialize, resetting a few values. Then the calling Sub is reading and handling the results from the form, followed by a Unload of the Form.
    I've tested it on 2 different (hardware) PC's with Windows XP Pro SP1 and Office XP / 2003 (all Dutch versions) and nothing else installed. The phenomenon is consistent on both PC's. Closing and restarting Word as Jefferson suggested and rebooting the PC's don't make any difference.

    Thanks
    JanB

  5. #5
    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: Focus problem? (Win XP / Word XP/2003)

    One other thing you could try: Export your UserForm, delete it from the template, then re-import it. Just in case it has become corrupted during its long journey to Word 2003.

    Can you tell, if the UserForm does not really have the focus, what does???

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

    Re: Focus problem? (Win XP / Word XP/2003)

    Thanks for the suggestion. I tried that too. Both manually and with VBA Code Cleaner. No joy.
    As I said in my original posting, the forms appears to have the focus (i.e. color of title bar). A thought: in Word 97 all forms are modal and I know that this is not the case in Word XP / 2003. Can this have any bearing on the problem? If so, what can be done to make sure the forms behave like a modal form in Word 97? (I can't use the test PC's today to experiment on the matter.)

    JanB

  7. #7
    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: Focus problem? (Win XP / Word XP/2003)

    Being modal is the default, so your code should run the same. Does it help if you add code to your Initialize procedure to set focus on a particular control?

  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: Focus problem? (Win XP / Word XP/2003)

    Thanks Jefferson. I'll give it a try.

    JanB

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

    Re: Focus problem? (Win XP / Word XP/2003)

    Sorry, that didn't work. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>
    The form is loaded first and Initialize fired, then changes are made to radiobuttons and textboxes, overriding the Setfocus in Initialize. I also tried to explicitly Setfocus on the last object changed in the form before activating it with Show, but that didn't help.

    During the test a collegue told me that he experienced a similar problem with one of the Lotus Notes panels. So maybe it's not a Word XP/2003 or VBA problem, but a Windows XP issue...? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Thanks anyway!
    JanB

  10. #10
    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: Focus problem? (Win XP / Word XP/2003)

    What is changing the radio buttons and textboxes? That sounds somewhat unusual.....

    Also, I'm still running Office XP, so there could be differences in the MSForms library for the next generation of Office/VBA that I'm not aware of.

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

    Re: Focus problem? (Win XP / Word XP/2003)

    I'll give you an example:

    Public Sub HandleFormXYZ()

    Load frmFormXYZ

    With frmFormXYZ
    .opt1.Caption = "One"
    .opt2.Caption = "Two"
    .opt3.Caption = "Three"
    .txtBox.txt = "Example"
    End With

    frmFormXYZ.Show

    'Rest of code
    End Sub

    I hope this clears up what I meant.

    Thanks
    JanB

  12. #12
    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: Focus problem? (Win XP / Word XP/2003)

    Gotcha. Put your SetFocus in the UserForm_Activate() event handler and see if that works. (The Activate event will fire when you .Show the form, but it also might fire at other times... I haven't used it much.)

Posting Permissions

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