Hi All.
I am trying to write a function to calculate the ISBN check digit and I cannot get my code to give the correct output.
The ISBN is calculated by weighting the numbers, dividing by 11 and the remainder is the check digit. Below is what I have, but Access is not returning the correct check digit.
The user enters a 9 digit number into a text box, presses a command button and the check digit is supposed to be returned.
Any help would be great. Thanks.
Command Button:
I am trying to write a function to calculate the ISBN check digit and I cannot get my code to give the correct output.
The ISBN is calculated by weighting the numbers, dividing by 11 and the remainder is the check digit. Below is what I have, but Access is not returning the correct check digit.
The user enters a 9 digit number into a text box, presses a command button and the check digit is supposed to be returned.
Any help would be great. Thanks.
Code:
Function ISBN_10(ByVal ISBN As String) As String
Dim checkDigitSubtotal As Integer
' Possible valid input includes 9-digits (no check digit)
Select Case Len(ISBN)
Case 9
' We're going to do the ISBN check digit calculation because the input doesn't have it.
Case Else
MsgBox ("You must enter 9 numbers")
End Select
checkDigitSubtotal = ((Val(Left(ISBN, 1))) * 10 + (Val(Left(ISBN, 2, 1))) * 9 + (Val(Mid(ISBN, 3, 1))) * 8 + (Val(Mid(ISBN, 4, 1))) * 7 + (Val(Mid(ISBN, 5, 1))) * 6 + (Val(Mid(ISBN, 6, 1))) * 5 + (Val(Mid(ISBN, 7, 1))) * 4 + (Val(Mid(ISBN, 8, 1))) * 3 + (Val(Mid(ISBN, 9, 1))) * 2) Mod 11
ISBN_10 = checkDigitSubtotal
End Function
Code:
Private Sub Command15_Click() Me.Text13 = ISBN_10(Me.Text12) Me.Text14 = [Text12] & [Text13] End Sub
Comment