Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

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

    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)

  3. #3
    Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  4. #4
    Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  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: User form behavior, Word 97 vs. Word 2000 (VBA/Office 97 & 2000)

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

    "HKEY_CURRENT_USERSoftwareMicrosoftOffice" & Application.Version & "Word"

  6. #6
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    *That* is a cool suggestion! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  7. #7
    Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

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

    The other thing you could do is use VBAs SaveSetting and GetSetting calls to store your data under the <font color=blue>HKEY_CURRENT_USERVB and VBA Program Settings </font color=blue>key

    StuartR

  9. #9
    Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

Posting Permissions

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