Validation.

  • Thread starter Thread starter sigh
  • Start date Start date
S

sigh

Hi,
I have a text box that have to be input as Alpha or
Asterisk "*". Here's my statment.

If Not TextBox1.Text Like "[a-z] then
msgbox...
End IF

In this statment I only allow to input the Alpha not
Asterisk. What statment I should use? so, I can either
input the Alpha or the Asterisk "*"?

Any help would be very appreciated.
 
sigh said:
Hi,
I have a text box that have to be input as Alpha or
Asterisk "*". Here's my statment.

If Not TextBox1.Text Like "[a-z] then
msgbox...
End IF

In this statment I only allow to input the Alpha not
Asterisk. What statment I should use? so, I can either
input the Alpha or the Asterisk "*"?

Any help would be very appreciated.

Do you want a single character in this text box? If so, have you tried

If Not TextBox1 Like "[a-z*]" Then
msgbox...
End If

For most purposes, you don't want to use the .Text property of the text
box. Use the (default) .Value property instead. You would only want to
use the .Text property if you were validating each keystroke as the user
is typing in the control.
 
Thanks. It work for 2 to 3 field. But I have 7 Fields to
Validate. Here's my Examples:

If Not Me.txtPostalCode.Value Like "[a-z*][#*][a-z*][#*]
[[a-z*][#*]" Then
MsgBox "It's no good"
Cancel = True
End If

My input are 1R12Z* and how come I got a mssage? Is't my
coding wrong?


-----Original Message-----
sigh said:
Hi,
I have a text box that have to be input as Alpha or
Asterisk "*". Here's my statment.

If Not TextBox1.Text Like "[a-z] then
msgbox...
End IF

In this statment I only allow to input the Alpha not
Asterisk. What statment I should use? so, I can either
input the Alpha or the Asterisk "*"?

Any help would be very appreciated.

Do you want a single character in this text box? If so, have you tried

If Not TextBox1 Like "[a-z*]" Then
msgbox...
End If

For most purposes, you don't want to use the .Text property of the text
box. Use the (default) .Value property instead. You would only want to
use the .Text property if you were validating each keystroke as the user
is typing in the control.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
sigh said:
Thanks. It work for 2 to 3 field. But I have 7 Fields to
Validate. Here's my Examples:

If Not Me.txtPostalCode.Value Like "[a-z*][#*][a-z*][#*]
[[a-z*][#*]" Then
MsgBox "It's no good"
Cancel = True
End If

My input are 1R12Z* and how come I got a mssage? Is't my
coding wrong?

Yes, your coding is wrong. First, you have an extra [ in the
expression, at least as you posted it, and second, where you have # in
the expression, you really need 0-9. Try this

If Not _
Me.txtPostalCode Like "[a-z*][0-9*][a-z*][0-9*][a-z*][0-9*]" _
Then

I might point out that the example you gave, "1R12Z*", will not pass
this edit; it begins number-alpha-number, where your expression
stipulates alpha-number-alpha.

By the way, please don't use the word "fields" when you aren't
referring to actual fields in a table or query. It's confusing.
 
Hi,
Thanks it works. But after all the input I enter. I
would like to put the space after the 3 letters.
Example: input data is r2r1g3 after I press enter it will
seperated and put the space between as r2r 1g3

How do I do code that?
Thanks

-----Original Message-----
sigh said:
Thanks. It work for 2 to 3 field. But I have 7 Fields to
Validate. Here's my Examples:

If Not Me.txtPostalCode.Value Like "[a-z*][#*][a-z*][#*]
[[a-z*][#*]" Then
MsgBox "It's no good"
Cancel = True
End If

My input are 1R12Z* and how come I got a mssage? Is't my
coding wrong?

Yes, your coding is wrong. First, you have an extra [ in the
expression, at least as you posted it, and second, where you have # in
the expression, you really need 0-9. Try this

If Not _
Me.txtPostalCode Like "[a-z*][0-9*][a-z*][0-9*][a- z*][0-9*]" _
Then

I might point out that the example you gave, "1R12Z*", will not pass
this edit; it begins number-alpha-number, where your expression
stipulates alpha-number-alpha.

By the way, please don't use the word "fields" when you aren't
referring to actual fields in a table or query. It's confusing.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
sigh said:
Hi,
Thanks it works. But after all the input I enter. I
would like to put the space after the 3 letters.
Example: input data is r2r1g3 after I press enter it will
seperated and put the space between as r2r 1g3

How do I do code that?

Try this:

'---- start of suggested code ----
Private Sub txtPostalCode_AfterUpdate()

If Not IsNull(Me.txtPostalCode) Then
If Mid(Me.txtPostalCode, 4, 1) <> " " Then
Me.txtPostalCode = _
Left(Me.txtPostalCode, 3) & " " & _
Mid(Me.txtPostalCode, 4)
End If
End If

End Sub
'---- end of suggested code ----

I put in an extra check to guard against the possibility that the field
already contains a space in the middle. Note that your BeforeUpdate
validation logic had better take this possibility into account also.
 
Back
Top