BeforeUpdate to determine length of entry and allow or not the entry

Ohi

Joined
Nov 14, 2009
Messages
5
Reaction score
0
Hi,

Briefly what I'm trying to do is determine if the user entered correctly the Vin number for a vehicle and warn them if they have or have not.

I can go about it two ways.

#1: There's a field in my table that references vehicle type, I only need to match if the VIN is 17 characters long on VehTypeID 1, if it's anything else, it can be any amount of characters.

Or #2, and the way I'm trying to do it cause tbh I really don't know what I'm doing is see if the vin is <= 16 and tell them theres too few characters and give them a msg to continue if it's what they meant to do, and another for >=18 stating there's too many characters.

Here's the code I'm trying to work with, any help would be fantastic!

Code:
If Len([Vin] <= 16) Then Cancel = False
MsgBox "Your VIN number contains LESS than the standard 17 characters  for a Passenger Vehicle.  You may modify your entry or continue if it is  not a Passenger Vehicle."
ELSEIf Len([Vin] >= 18) Then Cancel = False
MsgBox "Your VIN number contains MORE than the standard 17 characters  for a Passenger Vehicle.  You may modify your entry or continue if it is  not a Passenger Vehicle."
ELSEIf Me.Vin.Value = DLookup("[Vin]", "tblVehicles", "[Vin] = '" & Me.Vin.Value & "'") Then
Cancel = True
MsgBox "A duplicate VIN was found.  Check your entry and try again."
End If
End Sub
 
Last edited:

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