oh...my...God...I'm having my day with this crap...

R

rocco

I have a textbox where user enters a PIN

the sub pin value is tested in the BeforeUpdate event:

Private Sub pin_BeforeUpdate(Cancel As Integer)
If Not (pin.Text Like "*[A-Z]*[A-Z]*[A-Z]*" And pin.Text Like "*#*#*#*")
And Not pin.Text = vbNullString Then
msgtxt = "Il PIN digitato non rispetta il formato previsto." &
vbCrLf & _
"Inserimento annullato."
Call ShowMsg(red, msgtxt)
msgtxt = vbNullString
Cancel = -1
End If
End Sub

This will let me move on other controls if the value for the PIN is in the
right format or if I DELETE all what has been entered in the textbox and
exit, leaving it blank.
Blank...blank? Well, it looks like, but it is not!

I get an error in the AfterUpdate sub thus I have tested the pin.value in
the AfterUpdate procedure with this:
If pin.value = Null Then
MsgBox "NULL"
ElseIf pin.value = "" Then
MsgBox """"""
ElseIf pin.value = vbNullString Then
MsgBox "vbnullstring"
Else
MsgBox "other"
End If

and guess what... I get "other", which is gently pushing me to jump out of
the window.
What is "other" if the textbox is left blank, I mean I selected ALL the text
entered and pressed canc (or delete) ?! Are there ghost values?

rocco
 
D

Dirk Goldgar

rocco said:
I have a textbox where user enters a PIN

the sub pin value is tested in the BeforeUpdate event:

Private Sub pin_BeforeUpdate(Cancel As Integer)
If Not (pin.Text Like "*[A-Z]*[A-Z]*[A-Z]*" And pin.Text Like
"*#*#*#*")
And Not pin.Text = vbNullString Then
msgtxt = "Il PIN digitato non rispetta il formato previsto." &
vbCrLf & _
"Inserimento annullato."
Call ShowMsg(red, msgtxt)
msgtxt = vbNullString
Cancel = -1
End If
End Sub

This will let me move on other controls if the value for the PIN is in the
right format or if I DELETE all what has been entered in the textbox and
exit, leaving it blank.
Blank...blank? Well, it looks like, but it is not!

I get an error in the AfterUpdate sub thus I have tested the pin.value in
the AfterUpdate procedure with this:
If pin.value = Null Then
MsgBox "NULL"
ElseIf pin.value = "" Then
MsgBox """"""
ElseIf pin.value = vbNullString Then
MsgBox "vbnullstring"
Else
MsgBox "other"
End If

and guess what... I get "other", which is gently pushing me to jump out of
the window.
What is "other" if the textbox is left blank, I mean I selected ALL the
text
entered and pressed canc (or delete) ?! Are there ghost values?


This is your problem:
If pin.value = Null Then

Nothing is ever *equal to* Null. Change your test to:

If IsNull(pin.value) Then

.... and I expect you'll find that the control has a Null value.

In general , when you clear an Access text box, the value will become Null,
not a zero-length string.
 
R

rocco

you are right!!
God... I stumbled on the basic principles.
My brain was unbound, like my textbox.

Thanks!

Dirk Goldgar said:
rocco said:
I have a textbox where user enters a PIN

the sub pin value is tested in the BeforeUpdate event:

Private Sub pin_BeforeUpdate(Cancel As Integer)
If Not (pin.Text Like "*[A-Z]*[A-Z]*[A-Z]*" And pin.Text Like
"*#*#*#*")
And Not pin.Text = vbNullString Then
msgtxt = "Il PIN digitato non rispetta il formato previsto." &
vbCrLf & _
"Inserimento annullato."
Call ShowMsg(red, msgtxt)
msgtxt = vbNullString
Cancel = -1
End If
End Sub

This will let me move on other controls if the value for the PIN is in the
right format or if I DELETE all what has been entered in the textbox and
exit, leaving it blank.
Blank...blank? Well, it looks like, but it is not!

I get an error in the AfterUpdate sub thus I have tested the pin.value in
the AfterUpdate procedure with this:
If pin.value = Null Then
MsgBox "NULL"
ElseIf pin.value = "" Then
MsgBox """"""
ElseIf pin.value = vbNullString Then
MsgBox "vbnullstring"
Else
MsgBox "other"
End If

and guess what... I get "other", which is gently pushing me to jump out of
the window.
What is "other" if the textbox is left blank, I mean I selected ALL the
text
entered and pressed canc (or delete) ?! Are there ghost values?


This is your problem:
If pin.value = Null Then

Nothing is ever *equal to* Null. Change your test to:

If IsNull(pin.value) Then

... and I expect you'll find that the control has a Null value.

In general , when you clear an Access text box, the value will become Null,
not a zero-length string.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Top