swain90
01-15-2009, 11:24 AM
I have been given a database to do and it stores information on computer hardware, on my hardware details for i have got several different input boxes, but i have to include a serial number for the hardware. the serial number has to 6 characters long and CAN ONLY BE two letters followed by 4 numbers. i have got the code to check if this is correct and it is loaded into the After Update section on the form. My problem is that even if the serial number doesn't follow the two letters for numbers it still adds the record.
This is the code i have
Dim serialno As String
serialno = UCase(Serial_Number.Value)
If Len(serialno) = 6 Then
For a = 1 To 6
charater = Asc(Mid(serialno, a, 1))
'MsgBox Chr(charater) & " " & charater
If a = 1 Or a = 2 Then
If (charater >= 48 And charater <= 57) Then GoTo err
Else
If (charater >= 65 And charater <= 90) Then GoTo err
End If
Next
Else
err:
MsgBox "It Appears You Have Entered An Incorrect Serial Number" & vbNewLine & "The Serial Number Should Read; As 2 Letters 4 Numbers E.g. AA1234"
Cancel = 1
End If
please could you give me some tips into why it isn't working
This is the code i have
Dim serialno As String
serialno = UCase(Serial_Number.Value)
If Len(serialno) = 6 Then
For a = 1 To 6
charater = Asc(Mid(serialno, a, 1))
'MsgBox Chr(charater) & " " & charater
If a = 1 Or a = 2 Then
If (charater >= 48 And charater <= 57) Then GoTo err
Else
If (charater >= 65 And charater <= 90) Then GoTo err
End If
Next
Else
err:
MsgBox "It Appears You Have Entered An Incorrect Serial Number" & vbNewLine & "The Serial Number Should Read; As 2 Letters 4 Numbers E.g. AA1234"
Cancel = 1
End If
please could you give me some tips into why it isn't working