• User form behavior, Word 97 vs. Word 2000 (VBA/Office 97 & 2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » User form behavior, Word 97 vs. Word 2000 (VBA/Office 97 & 2000)

    Author
    Topic
    #374230

    I notice a small difference in the way Word reacts to identical code in 2000 vs. 97, and I wonder if anyone can help me understand what has changed and how to fix the problem in 2000. Here it is:

    We have several macros to make preparation of routine documents easier. On one user form, the user can choose between various closings to a letter. In 97, the last selection made is the default selection the next time the macro runs. In 2000, the same selection is always default (one of the list entries, but not the first). The user’s making a different selection has no effect on the default that comes up.

    Another instance is an option button. In 97, if the user selected the option button once, the next time the user ran the macro, the option would be selected. In 2000, it never is.

    Any ideas on what changed and how I can make the behavior of Word 2000 consistent with that of 97 in these instances?

    Thank you
    Michael Dagley

    Viewing 0 reply threads
    Author
    Replies
    • #604772

      Michael,

      Don’t know if the following is helpful, but the behavior you describe for the forms in Word 97 doesn’t sound in keeping with the way one would expect a form to behave – every time you initialize a form, you are creating a new instance of that form (class) and the values of things like checkboxes and option buttons will always be set to the default settings that were set at design time. (The only exception being is you have code running, as part of the initialization process, which sets the controls to different settings, or retrieves stored values from something like the registry or an .ini file, which are then used to change the settings.)

      I don’t have Word 97 anymore to test with, but based on the above it sure sounds like something else is going on with the Word 97 forms – are you possibly handling the showing and hiding of them differently between Word 97 and Word 2000? – for instance, if you merely hide the form rather than unload it, then the next time you show it, it will display the behavior you are reporting for the Word 97 forms.

      Gary

      (btw I will be offline for the next couple of days)

      • #604814

        Thanks for your response. As it happens, the code used in both 97 and 2000 for this is identical, but it acts differently in 97. As I understand it, the following command set the form up with the former value that was used:

        TxtSalutation.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
        ComboClosing.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection

        TxtSalutation is the name of the text box for the salutation, and ComboClosing is the name of the combo box for the closing.

        As for how the form is unloaded, it is not hidden but unloaded in all cases. As I said, the code is identical, which makes me think there’s something I need to change to adapt it to 2000.

        Thanks again for you help!

        Regards
        Michael Dagley

        • #604833

          In case anyone is interested in the answer to this one, I finally found it. The problem had to do with how the information for the user form was saved. As you probably know, one can store values in several places for later retrieval after a macro ends — document variables or properties, autotext entries, and the Windows registry. Since many items in the macros were saved as autotext, I assumed that had to be where I should look. It turned out to be in the Windows registry.

          In every reference to the registry in the macro such as this one:

          HKEY_CURRENT_USERSoftwareMicrosoftOffice8.0Word

          I changed 8.0 to 9/0, the result being:

          HKEY_CURRENT_USERSoftwareMicrosoftOffice9.0Word

          Now everything works just fine. I should have checked this in the first place.

          Thanks for your help!
          Michael Dagley

          • #605113

            Planning ahead, perhaps it’s best to do this:

            “HKEY_CURRENT_USERSoftwareMicrosoftOffice” & Application.Version & “Word”

            • #605491

              *That* is a cool suggestion! grin

            • #605493

              That’s a great idea. If the previous programmer had used this method, I believe I’d have figured the problem out a lot more quickly.

              There’s a question in my mind whether it is even best to store things in the registry since problems such as this result. One lounger wrote me privately to recommend saving such setting in a text file, which makes a lot of sense since it would be impervious to version changes. It would be a lot of work to change at this point, but it’s worth considering.

              Thanks to everyone for their help.

              Regards
              Michael Dagley

            • #605499

              The other thing you could do is use VBAs SaveSetting and GetSetting calls to store your data under the HKEY_CURRENT_USERVB and VBA Program Settings key

              StuartR

            • #606761

              Thanks for the suggestion. I think, once I get a chance to breathe, I’ll rewrite the macros to use text files. Based on several things I’ve read, it seems the registry is not the best place to keep such information.

              Thanks
              Michael Dagley

    Viewing 0 reply threads
    Reply To: User form behavior, Word 97 vs. Word 2000 (VBA/Office 97 & 2000)

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

    Your information: