Validating Data on Exit

shewolf

Registered User.
Local time
Today, 12:35
Joined
Dec 3, 2004
Messages
25
I'm trying to figure out how to validate a field to make sure the users are not entering any blank spaces into the field. I've tried setting the mask up as "aaaaaa" but it still lets the user enter a blank space.

I've also tried building an event procedure to run on exit that reads:

Private Sub Barcode_Exit(Cancel As Integer)
Dim LPos As Integer
Dim LChar As String
Dim LValid_Values As String

'Start at first character in Barcode
LPos = 1

'Set up values that are considered to be alphanumeric
LValid_Values = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-.0123456789"

'Test each character in Barcode
While LPos <= Len(pValue)

'Single character in Barcode
LChar = Mid(pValue, LPos, 1)

'If character is not alphanumeric, return FALSE
If InStr(LValid_Values, LChar) = 0 Then
AlphaNumeric = False
Exit Function
End If

'Increment counter
LPos = LPos + 1

Wend

'Value is alphanumeric, return TRUE
AlphaNumeric = True
If AlphaNumberic = False Then
MsgBox "Barcode cannot contain blank spaces, only letters and numbers.", vbExclamation, "Barcode Field Value"
Else
End Sub

****
However the message box does not come up and the form will not then let you get out of that field.

Any ideas? I've been checking on this field by running a query and then manually correcting the errors but I would rather that the DB check and force correction at the time the data is entered.

Any and all help will be greatly appreciated.

Charis
 
Try an input mask of AAAAAA (capital not lower case).

Stopher
 
Use the KeyDown or KeyPress event to test what key the user has hit. Search around for there are plenty of sample code on how to do it.
 
Neither aaaaaa or AAAAA solve my problem. They both allow the user to enter a blank space into the field. I want them only to be able to enter letters or numbers. There cannot be any other characters or blank spaces in the field. Also AAAAA makes that many characters required and the number of characters has to be able to vary, some may have 7 others 10.
 
shewolf said:
Neither aaaaaa or AAAAA solve my problem. They both allow the user to enter a blank space into the field. I want them only to be able to enter letters or numbers. There cannot be any other characters or blank spaces in the field. Also AAAAA makes that many characters required and the number of characters has to be able to vary, some may have 7 others 10.
How about a validation rule of:
InStr(1,[myField]," ")=0

where myField is the name of the field you are validating
hth
Chris
 
ghudson said:
Use the KeyDown or KeyPress event to test what key the user has hit. Search around for there are plenty of sample code on how to do it.
Did you try my suggestion? The code I posted in the Input Mask question thread will do exactly what you want.
 

Users who are viewing this thread

Back
Top Bottom