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

    Author
    Topic
    #399527

    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

    Viewing 2 reply threads
    Author
    Replies
    • #772338

      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?

      • #772844

        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

        • #772846

          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???

          • #772881

            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

            • #773267

              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?

            • #774185

              Thanks Jefferson. I’ll give it a try.

              JanB

            • #774186

              Thanks Jefferson. I’ll give it a try.

              JanB

            • #774272

              Sorry, that didn’t work. sad
              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…? confused

              Thanks anyway!
              JanB

            • #774635

              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.

            • #774963

              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

            • #775194

              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.)

            • #775195

              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.)

            • #774964

              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

            • #774636

              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.

            • #774273

              Sorry, that didn’t work. sad
              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…? confused

              Thanks anyway!
              JanB

            • #773268

              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?

          • #772882

            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

        • #772847

          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???

      • #772845

        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

    • #772758

      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.

    • #772759

      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.

    Viewing 2 reply threads
    Reply To: Focus problem? (Win XP / Word XP/2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: