Help! Form Field validation

Graham63

Registered User.
Local time
Today, 19:07
Joined
Mar 22, 2012
Messages
20
Hi Everyone,
Self teaching and fairly new to this, I need some help with validating a field in a form which will hold a Barcode reference(not the Barcode active x) which will be scanned in. The first 2 lead characters of the 8 digit barcode ref which can be a combination of numbers or letters identify a type of device, if the device type is entered in its field I need to know if the Barcode is of the correct type for this device, I have been playing with something like this in the Before Update event,
If Me.Device Type = "6000/LED" Then
Me.Device_Label.Left (, 2) = "82"
Else
MsgBox "Type Error! Please scan a barcode that matches this Device Type"
End if
There are about 15 different Device Types in a column in a different underlying table from that of the form with a relationship called "Equipment" and the lead characters have been entered in a column next to Device_Type. How can I crack this, Is my approach wrong?
Many thanks! Graham63:confused:
 
Sorry if I have misunderstood, but from your description it sounds like the user will enter both a device type, and a barcode, and you want to check if they match.

In your code you can get the first two barcode digits from the Device_Type table using something like this (where "FirstTwoDigits" is a field containing the first two digits of the relevant barcode).

FirstTwoDigits = DLookup("FirstTwoDigits","Device_Type_Table", "Device_Type=" & Me!Device_Type)

Now you can check if this matches the entered barcode:

If left(Me!Barcode,2) Like FirstTwoDigits Then
valid
Else
not valid
End If
 
Thanks for your reply, sparks80,
I dont feel this code I put in the Before Update Event of the "Sticker_Barcode" form field?? is far away. Device_Lead is my ref for FirstTwoDigits. this returns, Runtime error 3075, syntax error(missing operator)in query expression. Device_Type '6000MCP/WP' What could I be missing? Your help is very much appreciated!
Graham63
Private Sub Sticker_Barcode_BeforeUpdate(Cancel As Integer)
Device_Lead = DLookup("Device_Lead", "Equipment", "Device_Type=" & Me!Device_Type)
If Left(Me!Sticker_Barcode, 2) Like Device_Lead Then
Me.Sticker_Barcode = True
Else
MsgBox "Type Error, please enter a matching Barcode reference"
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom