Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Userforms, variables & multiple documents (WORD 97/2000)

    I have a template that contains two userforms (created using the VBA under WORD2000/97), i.e. Userform1 and Userform2. I have also defined my own macros and some 'Public' varaibles that I use within these macros.

    The problem:

    When I open a document (using the defined template) it displays a form 'Userform1' to the screen and gets information from the user which populates some custom properties. It also sets up some 'public' variables (defined as Public p_FileSaved As Boolean & Public p_PostProcess As Boolean) on top of a module.

    If I open another document using the same template, I find that the Userform1 takes its properties from the first document opened and the public variables also contain the values updated by opening document 1 (whereas I would have expected it to have default values for the second document - which I would update after displaying the Userform1 to the screen for the 2nd document). I hope the above makes sense.

    I would have expected that document1 and document2 would have its own Userform1, Userform2, public variables p_FileSaved, p_PostProcess but it seems to share these between both/multiple documents? Any ideas why and what is the potential solution please. Surely, even though the forms are designed within a template, each opened document should have a copy of its own Userform1, Userform2 and the public variables.

    I have also found that when I try to display the form on the second document (using a macro), it first jumps to the first document, display the form but contains properties from the second document. It doesn't update the document correctly even if properties have changed. This is a real muddle & pain.

    I am in a real jam here so any ideas would be more than welcomed.

    Please tell me if I am doing something wrong or I need to set something up to indicate the each document should have its own "workspace of userforms and variables".

    Thanks in advance.

    Robie
    Thanks.
    Robie

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

    Re: Userforms, variables & multiple documents (WORD 97/2000)

    You get this problem If you hide the form after using it in Document 1.

    After you finish using the form in Document 1 you must unload it. Then it will load a new instance of the form when you show it from Document 2.


    StuartR

Posting Permissions

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