- The first 3-digit is Airline Prefix which is unique for each airline
- The next 7-digit is the Air Waybill's Serial Number, and
- The last digit is the Check digit, which calculated by dividing 7-digit Serial Number by 7 and the reminder determines the Check digit e.g.: 1234567 divided by 7 is 176366 with reminder 5, hence the Serial Number + Check Digit is 1234567-5.
Since the Serial Number is divided by a constant 7, the remainder will always be a number fewer than 7 or any number between 0 and 6. Using Microsoft Access Database for this experiment, the VBA Script would be like this:
If Right(DMax("fieldName", "tableName"), 1) = 6 Then
Me.AWBNumber = DMax("fieldName", "tableName") + 4
Else
Me.AWBNumber = DMax("fieldName", "tableName") + 11
End If
The first If condition, look for an Air Waybill field name where you store its numbers, get a maximum value from a table, extract the last digit to the right, if it is 6 which is the maximum digit number it can be for a check digit, then the next Air Waybill number should be the maximum Air Waybill number added by 4. It will the reset the last digit to 0.
Else, it should be the maximum Air Waybill number added by 11.
As the Air Waybill number increases with this routine, it will always loop back to last digit of 0.