Can't get this input mask quite right

C

CW

I have a control where we need the value to be formatted as follows:

Maximum of 8 characters (but could be just one i.e. anything from 1-8)
Can be either letter or digit
No spaces between characters
Upper case

I have tried >aaaaaaaa but that allows spaces so no good

Thanks
CW
 
P

Peter Hibbs

CW

Rather than use an input mask (which can be a bit messy sometimes) you
could add this code to the KeyPress event of the Text box control.

Private Sub YourControlName_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If Chr(KeyAscii) Like "[!0-9A-Z]" And _
KeyAscii <> vbKeyBack Then KeyAscii = 0
End Sub

where YourControlName is the name of your text field. This will allow
ONLY the characters 0-9 and A-Z to be entered in the field.

To limit the number of characters to 8 (assuming this control is bound
to a field in a table) set the Field Size property of the field in the
table to 8.

HTH

Peter Hibbs.
 
C

CW

Did that help? I'll say it did - perfect!
That'll save us no end of malformed records
MANY THANKS
CW

Peter Hibbs said:
CW

Rather than use an input mask (which can be a bit messy sometimes) you
could add this code to the KeyPress event of the Text box control.

Private Sub YourControlName_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If Chr(KeyAscii) Like "[!0-9A-Z]" And _
KeyAscii <> vbKeyBack Then KeyAscii = 0
End Sub

where YourControlName is the name of your text field. This will allow
ONLY the characters 0-9 and A-Z to be entered in the field.

To limit the number of characters to 8 (assuming this control is bound
to a field in a table) set the Field Size property of the field in the
table to 8.

HTH

Peter Hibbs.

I have a control where we need the value to be formatted as follows:

Maximum of 8 characters (but could be just one i.e. anything from 1-8)
Can be either letter or digit
No spaces between characters
Upper case

I have tried >aaaaaaaa but that allows spaces so no good

Thanks
CW
 
Top