String validation

M

mick.whyte

Apologies for an overly simple question but:

If I want to validate an entry on a form (to a table) how do I
validate it so it has to be text. Do I have to list all the acceptable
ASCII characters or is there a built in function to do this?

Thanks

Mick
 
A

Albert D. Kallal

Apologies for an overly simple question but:

If I want to validate an entry on a form (to a table) how do I
validate it so it has to be text. Do I have to list all the acceptable
ASCII characters or is there a built in function to do this?

Well, if you are validating the entry to a list from a table, then why do we
care if it is numbers, text or whatever? You simply limit the values entered
to the table list..and you done? (am I missing something here?).

The most easy way to do this is simply drop a combo box into the form, let
the wizard build this box. You can set the "limit to list" = yes, and then
users will not be able to enter anything else, but a value tested against
that table....

I not really sure why you going off on a tangent about text, numbers or
whatever, since in the next sentence you tell me you have list to validate
the given entry against.

if you did not have that list, then you could use a input mask to restrict
the entry to numbers, or text only, but we don't seen to need that ability
with a given table list already to validate against.
 
M

mick.whyte

Well, if you are validating the entry to a list from a table, then why do we
care if it is numbers, text or whatever? You simply limit the values entered
to the table list..and you done? (am I missing something here?).

The most easy way to do this is simply drop a combo box into the form, let
the wizard build this box. You can set the "limit to list" = yes, and then
users will not be able to enter anything else, but a value tested against
that table....

I not really sure why you going off on a tangent about text, numbers or
whatever, since in the next sentence you tell me you have list to validate
the given entry against.

if you did not have that list, then you could use a input mask to restrict
the entry to numbers, or text only, but we don't seen to need that ability
with a given table list already to validate against.

Hi

The entry is for a username that I only want to comprise of letters,
hence the need for the form to validate on input

Thanks

Mick
 
P

PeteyP

Not sure which version of Access you are using (or if it matters), but here
is an example I found on validation of a form control for text:

StrComp(UCase([LastName]),[LastName],0) = 0

Which means that data in the LastName field must be entered in uppercase
letters.
 
D

Dave Emmert

I can think of two different methods:

1) Use the keypress event to cancel any unwanted characters. I've done
this for fields that I wanted only numbers in.

2) In the AfterUpdate event:

if textbox1.value like "*[0-9]*" then
msgbox "Invalid userid!!! Numerals are not allowed in userids!"
textbox1.value = ""
end if

Dave
 
M

missinglinq via AccessMonster.com

Where "Letters" is the name of the control holding the string you want
checked. The code steps thru the string, one character at a time, and checks
to be sure the characters aren't numeric.

'************************ Code ***************************
Private Sub Letters_BeforeUpdate(Cancel As Integer)
Dim I As Integer
Dim Hits As Integer
Hits = 0

'This insures that no characters are numeric

For I = 1 To Len(Me.Letters.Value)
If IsNumeric(Mid(Me.Letters.Value, I, 1)) Then
Hits = Hits + 1
End If
Next I

If Hits > 0 Then
MsgBox "All characters must be Letters"
Cancel = True 'Sets focus back on the control for another entry attempt
Me.Letters.SelStart = 0
Me.Letters.SelLength = Len(Me.Letters.Value)
End If
End Sub
 
J

John Nurick

Hi Mick,

The entry is for a username that I only want to comprise of letters,
[snip]

Use a validation rule (on the field in underlying table, and probably
also on the textbox on the form) of

Not Like "*[!A-Za-z]*"

(If you're using ADO, use "%[!A-Za-z]%" .)
 
Top