input mask and validation

cutsygurl

New member
Local time
, 19:50
Joined
Oct 5, 2004
Messages
6
I need help with my visual basic. Please.
I have a form that I want to restrict to only put a certain type of data in to the fields. And if that input mask is not correct to delete whatever has been put in that field and keep the focus at that field. The only way to go to the next field or even see data in the field is that if the correct data that matches the input mask has been entered.

This is what I have so far, but it doesn’t work.
Code:
Private Sub Cabinet_S_N_BeforeUpdate(Cancel As Integer)
If Me![Cabinet S/N].InputMask <> "000L0009" Then
    Cancel = True
    Me![Cabinet S/N].Undo
    End If
End Sub

Thanks in advance
 
Why are you testing whether a control's input mask property matches something? That wouldn't have anything to do with the data. Can you explain further?
 
I think she may be confused with the purpose of the input mask. When you assign an input mask to a control, the control will automatically check to see if the text you are trying to store in it conforms to the mask or not.

If you have already assigned the Input Mask of "000L0009" to your [Cabinet S/N] control, then what your code is saying is:

Code:
IF "000L0009" <> "000L0009" THEN
...

The IF statement will never follow through because the input mask is always set to the value that you set it to.

Please elaborate on what you are trying to accomplish here.
 
Sorry for the confusion. I'll try to explain better.
I have three fields "Cabinet S/N", "Work Number", and "Name" that will all be barcoded into a database. I don't want people to be entering the wrong barcode in the wrong field. I want to restrict the fields to only accept the type of data. Cabinet S/N will always have 3 numbers, the letter "A", and then three numbers (ex: 123A456). Work Number will always have 9 digits and start with 10004. And the Name field will be coming from a list. So if the wrong type of data in barcoded in, the field will stay empty until the correct data is entered in.
 

Users who are viewing this thread

Back
Top Bottom