On Change of a control

  • Thread starter Thread starter Manuel
  • Start date Start date
M

Manuel

Hi everybody,

I have a text box control that I want to perform a
certain subroutine on change, reflecting if the previous
was wiped out. For that and to test it I wrote in Visual
Basic Code for that Private Sub text1_Change()as follows

If [text1] = Null Then
MsgBox "update"
Else
MsgBox "don´t update"
End If

When I deleted the contents of the text box, the
message "don't update" came up.

So I tried instead the following;

If [text1] ="" Then
MsgBox "update"
Else
MsgBox "don´t update"
End If

Still the message "don´t update" came up.

What should I write to reflect the value of the text box
when it´s contents are deleted. It is not recgnizing
(Null) or ("").

Thanks for any help.

Manuel
 
The Change event fires each time the user types (or erases) a character in
the textbox. You'd normally want to wait until the user has *finished*
typing his changes (or erasures), before you take further action. For that
purpose, use the BeforeUpdate or AfterUpdate events, instead of the Change
event.

IF BLAH = NULL will never work, since nothing is ever equal to null - not
even null itself! (So IF NULL = NULL will not work either). IF BLAH = ""
will work if BLAH is an empty string, but not if it is a null variant. So
the safest way, if you're not sure what type the item is, is: IF NZ (BLAH,
"") = "" (or, IF BLAH & "" = "").

HTH,
TC


Hi everybody,

I have a text box control that I want to perform a
certain subroutine on change, reflecting if the previous
was wiped out. For that and to test it I wrote in Visual
Basic Code for that Private Sub text1_Change()as follows

If [text1] = Null Then
MsgBox "update"
Else
MsgBox "don´t update"
End If

When I deleted the contents of the text box, the
message "don't update" came up.

So I tried instead the following;

If [text1] ="" Then
MsgBox "update"
Else
MsgBox "don´t update"
End If

Still the message "don´t update" came up.

What should I write to reflect the value of the text box
when it´s contents are deleted. It is not recgnizing
(Null) or ("").

Thanks for any help.

Manuel
 
Thanks.

I had it going with "If IsNull(Blah) Then" but I was
lucky that it really was a null. Already changed it to
yours and it works obviously OK.
Thanks again

Manuel
 
No probs, glad it helped.

TC


Thanks.

I had it going with "If IsNull(Blah) Then" but I was
lucky that it really was a null. Already changed it to
yours and it works obviously OK.
Thanks again

Manuel
 
Back
Top