Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2003
    Location
    Kansas City, Missouri
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing check box value prevents user change (Word 97 SR-2)

    I am having some trouble with a form in Word 97 VBA.

    My goal is to have a form with a check box, a text box, and a label. If the user types in a value in the text box, then the check box is set to true. The label's caption would change depending on the value of the text box. In testing this code, I can type in the text box and have the check box change to True.

    However, once I do that, I am unable to uncheck the check box with the mouse. I know the value is False because I have code which changes the text box's value and the label's caption. However, the box does not visibly look false, which will definitely confuse users.

    So, is there something about check boxes that I need to learn? Obviously, I don't fully understand this feature (indeed, there is a lot of VBA I don't know).

    If it helps, I'll include copies of my code here.

    Private Sub txtTable_Change()
    lblTableExample.Caption = "Table " & txtTable.Value
    chkTable.Value = True
    End Sub

    Private Sub chkTable_Change()
    If chkTable.Value = False Then
    lblTableExample.Caption = "No change"
    txtTable.Value = ""
    Else
    lblTableExample.Caption = "Table 1"
    txtTable.Value = "1"
    End If
    End Sub


    Kevin Elmore

    PS, as a bonus problem (which I'm going to tackle next), when I make a change to the text box, the value that comes up is always "1." After that first keypress, any other numbers I type in are fine. I'm sure I'll kick myself when I look at this one.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing check box value prevents user change (Word 97 SR-2)

    As far as I can see, both event macros are going to call each other in an endless loop because both make a change to the other control, thus firing their change event subs over and over again..

    It may be better to prevent that like this:

    'At top of Userform's module:

    Dim bDisableEvents as Boolean

    Private Sub txtTable_Change()
    If bDisableEvents then Exit Sub
    bDisableEvents=True
    lblTableExample.Caption = "Table " & txtTable.Value
    chkTable.Value = True
    bDisableEvents=False
    End Sub

    Private Sub chkTable_Change()
    If bDisableEvents then Exit Sub
    bDisableEvents=True
    If chkTable.Value = False Then
    lblTableExample.Caption = "No change"
    txtTable.Value = ""
    Else
    lblTableExample.Caption = "Table 1"
    txtTable.Value = "1"
    End If
    bDisableEvents=False
    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Star Lounger
    Join Date
    Apr 2003
    Location
    Kansas City, Missouri
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing check box value prevents user change (Word 97 SR-2)

    Jan,

    It works like a charm. Thank you very much.
    And now I have something to study and learn.

    Kevin

Posting Permissions

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