Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    477
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Hides and doesn't save variable values (Word 2000 VBA)

    I'm definitely in learning mode here and have gotten stumped. I have attached a portion of my project to reproduce the issues.

    Issue 1: Follow these steps:
    a. Click on the Run Form button to run the main form (frmDocumentFormatMain).
    b. Click the Options button or the check box. The "Cover/Copyright Page Options" form appears.
    c. Try to click any check box or button, or try to change the focus using the TAB key. The "Cover/Copyright Page Options" form disappears. The first form is still displayed, but the focus is on the document.
    KEEP GOING OR YOU MAY MISS THE REALLY WEIRD PART.
    d. Again click the Options button or the check box. The "Cover/Copyright Page Options" form appears. This time you can click check boxes or buttons to your hearts content. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    This seems to happen every other time I open the "Cover/Copyright Page Options" form. In other words, if you keep the main form open, you can repeat steps b through d to your hearts content and get the same results time after time.
    (The OK button doesn't work yet so don't worry about that.)

    Issue 2:
    The second issue comes at this point. I have set up some boolean variables to use so that when I hit the "Cancel" button, these values can be returned to whatever they were when the form was activated. However, when I hit the Cancel button, and then click the Options button or check box again, the form displays with both check boxes cleared.

    Thanks for any help you can give!!
    Troy
    Attached Files Attached Files

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    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: Form Hides and doesn't save variable values (Word 2000 VBA)

    I think it was related to the Exit code for the Cancel button in the second form. Maybe. But see attached, which probably is closer to what you are looking for, and has a few questions, too.
    Attached Files Attached Files

  4. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    477
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Hides and doesn't save variable values (Word 2000 VBA)

    <P ID="edit" class=small>Edited by TroyWells on 03-Sep-01 18:53.</P>UPDATE: I had the wrong attachment attached. Sorry for any confusion. <img src=/S/bash.gif border=0 alt=bash width=35 height=39>
    Troy

    I agree that my problems where caused by my use of the "Exit" event. So I changed the "Exit Event code to the "Terminate" event.

    KEY: What I was trying to accomplish with this code is to make the control menus (right-click on the title bar and click "Close", ALT+F4, and the little "X" in the upper right corner do the same thing as the "Cancel" button. (Sorry, I probably should have mentioned this in my first post.)

    PROBLEM: When I put the same code in the "Terminate" event, as soon as I show the main form, it resets all the properties to whatever they were when the form was activated.

    For example:
    1. Run the form.
    2. Click on the Options button or the check box.
    3. Click a check box, and click OK.
    4. Click the Options button.
    5. Right-click on the title bar and click "Close", or press ALT+F4, or click the little "X" in the upper right corner.
    The main form reappears but the options on the other form are reset to their default (i.e. it doesn't retain the check mark you applied in step 3.

    I tried commenting out "frmFormatDocumentMain.Show", but all that does is return the focus to the document with the form still visible. Once I click the form again (i.e. the form gets the focus) it resets everything.

    I have attached the document including changes I made in response to your first reply.

    Thanks again for your help!!
    Troy
    Attached Files Attached Files

  5. #4
    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: Form Hides and doesn't save variable values (Word 2000 VBA)

    Weird. The value of the global variables AddCover and AddCopyright changes to False between these two message box test in the main form's Activate procedure:

    <pre>Private Sub UserForm_Activate()
    MsgBox "Activation 1:" & vbCrLf & "Cover = " & AddCover & vbCrLf & "Copyright = " & AddCopyright
    If AddCover = True Then
    frmOptionsCoverCopyright.cbxAddCover.Value = True
    Else
    frmOptionsCoverCopyright.cbxAddCover.Value = False
    End If
    If AddCopyright = True Then
    frmOptionsCoverCopyright.cbxAddCopyright = True
    Else
    frmOptionsCoverCopyright.cbxAddCopyright = False
    End If
    MsgBox "Activation 2:" & vbCrLf & "Cover = " & AddCover & vbCrLf & "Copyright = " & AddCopyright</pre>

    And they don't if you don't execute that code:
    <pre>Private Sub UserForm_Activate()
    MsgBox "Activation 1:" & vbCrLf & "Cover = " & AddCover & vbCrLf & "Copyright = " & AddCopyright
    'If AddCover = True Then
    ' frmOptionsCoverCopyright.cbxAddCover.Value = True
    'Else
    ' frmOptionsCoverCopyright.cbxAddCover.Value = False
    'End If
    'If AddCopyright = True Then
    ' frmOptionsCoverCopyright.cbxAddCopyright.Value = True
    'Else
    ' frmOptionsCoverCopyright.cbxAddCopyright.Value = False
    'End If
    MsgBox "Activation 2:" & vbCrLf & "Cover = " & AddCover & vbCrLf & "Copyright = " & AddCopyright</pre>

    Why on earth would that be?? Luckily, there appears to be no reason to have this in the main form rather than the second form.

    I still think the assignment statements in the Cancel and Terminate procedures should be deleted: both should "discard" whatever the user did.

  6. #5
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    477
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Hides and doesn't save variable values (Word 2000 VBA)

    Regarding the "Weird" comment, I must have created this and moved it somewhere else and forgot to remove it here. You are right to say that is unnecessary. Good catch!!

    Regarding the Cancel and Terminate issue: You were right!! I had a lot of code in there I didn't need. Once I removed this code the problem went away. I still don't know which part of the code that I deleted caused the problem I was experiencing, but I think it would be best to not worry about that until it happens again.

    Thanks again for all your help!!
    Troy

Posting Permissions

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