Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disabling a Text Box Change Event (2003)

    In the startup form of the attached mdb, I'd like to have a message box pop up if the user tries to edit text boxes for any day except the last one available.
    As an example, I've prepared the following code for the Change event of the TERMICA text box.
    <font color=448800>Private Sub Termica_Change()
    If Giorno < DMax("Giorno", "previsioni") Then
    If MsgBox("Are you sure you want" & vbCr & "to modify the value?", vbDefaultButton1 + vbExclamation + vbYesNo, "Warning!") = vbYes Then
    End If
    End If
    End Sub </font color=448800>
    How do you disable the Change event if the user selects YES so he/she can fill the text box without having the message box popping up again at every keystroke?

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling a Text Box Change Event (2003)

    One way to do it would be to set a module level variable = to say 1.
    Check to see if that variable = 1 before running the stattements to create the message box.
    Richard

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Disabling a Text Box Change Event (2003)

    Try this:

    - At the top of the module:

    Private blnAllowEdit As Boolean

    - In the Termica_Change event procedure:

    Private Sub Termica_Change()
    If blnAllowEdit Then
    Exit Sub
    End If
    If Giorno < DMax("Giorno", "previsioni") Then
    If MsgBox("Are you sure you want" & vbCr & "to modify the value?", _
    vbExclamation + vbYesNo, "Warning!") = vbYes Then
    blnAllowEdit = True
    Else
    Me.Undo
    End If
    End If
    End Sub

    - Create an On Current event procedure for the form to reset blnAllowEdit:

    Private Sub Form_Current()
    blnAllowEdit = False
    End Sub

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disabling a Text Box Change Event (2003)

    Thank you Hans and Richard,
    shouldn't it be better to apply the undo method only to the control affected by the event, i.e. Me!Termica.Undo
    rather than to the whole form? I ask this because if the Undo method is applied to a form, all changes to the current record are lost.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Disabling a Text Box Change Event (2003)

    Correct.

Posting Permissions

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