Text Box Enter and Exit Events

  • Thread starter Thread starter dunnerca
  • Start date Start date
D

dunnerca

I am writing code in which I want to check the text value of a text box upon
the exit from a text box against the value that was there upon the Enter
event. I seem to be having a problem passing this variable from the Enter
event procedure to the Exit event procedure. Anything obvious I'm missing?
Also, is there a better way to do what I'm trying?
 
Try something like......

' at top of userform code module
Dim TextBefore As String


Private Sub TextBox1_Enter()
TextBefore = Trim(TextBox1.Value)
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Trim(TextBox1.Value) = TextBefore Then
MsgBox "No Change"
Else
MsgBox "Changed"
End If
End Sub

Private Sub UserForm_Initialize()
TextBefore = Trim(TextBox1.Value)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top