Requiring alpha data entry

  • Thread starter Thread starter Dudley
  • Start date Start date
D

Dudley

I want to give an error message when a user does not enter alpha characters
only, but my code does not work.

If Type1 = 1, then the user should enter the first three letters of the town
of birth in Data1.

If Forms![Director1 John]![Director1Type1] = "1" And _
(Forms![Director1 John]![Director1Data1] < Asc("64")) And
(Forms![Director1 John]![Director1Data1] > Asc("91")) _
Or (Forms![Director1 John]![Director1Data1] < Asc("96")) And
(Forms![Director1 John]![Director1Data1] > Asc("123")) Then

fnErrorCheck = False
MsgBox "Invalid town of birth"
Exit Function
Else
fnErrorCheck = True
End If


Many thanks if anyone can help.

Dudley
 
You need CHR$(number) not ASC("number")
Towns can also contain hyphens and apostrophes I believe.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
Thanks very much for your help. I take your point about hyphens etc, but I
think it is simpler to limit users to alpha characters.

Dudley

Dorian said:
You need CHR$(number) not ASC("number")
Towns can also contain hyphens and apostrophes I believe.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


Dudley said:
I want to give an error message when a user does not enter alpha characters
only, but my code does not work.

If Type1 = 1, then the user should enter the first three letters of the town
of birth in Data1.

If Forms![Director1 John]![Director1Type1] = "1" And _
(Forms![Director1 John]![Director1Data1] < Asc("64")) And
(Forms![Director1 John]![Director1Data1] > Asc("91")) _
Or (Forms![Director1 John]![Director1Data1] < Asc("96")) And
(Forms![Director1 John]![Director1Data1] > Asc("123")) Then

fnErrorCheck = False
MsgBox "Invalid town of birth"
Exit Function
Else
fnErrorCheck = True
End If


Many thanks if anyone can help.

Dudley
 
Back
Top