Data Validation

S

Simon

G'day everyone.

Wondering how I limit someone from entering in non numeric or alphabetic
characters into a textbox on a form. Do I do this within a form or in my
table design.

I'm wanting the user to be able to use:
a to z
A to Z
1 to 0

I don't want them to use !@#$%^&*()'";:,./<>?{}[] etc etc

Hope you can help,
Cheers
Simon
 
N

Nikos Yannacopoulos

Simon,

To the best of my knowledge, there's no way it can be done
through format; I believe you'll have to use some code to
read the text string, loop through each character and
check if it is within the acceptable ranges. It should
look omething like:

strg = Forms("Formname").Controls("InputBox") = ""
For i = 1 To Len(strg)
ltr = Asc(Mid(strg, i, 1))
If ltr < 48 Or (ltr > 57 And ltr < 65) Or (ltr > 90
And ltr < 97) Or ltr > 122 Then
MsgBox "Invalid characters in string." & Chr(10)
& "Pls try again."
Forms("Formname").Controls("InputBox") = ""
Exit For
End If
Next

and should be fired by the on change event of the input
box.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top