K
kyle775
Hi, ive build a query using the following module to calculate the
check digit (using mod 10) of an 11 digit upc number. In excel i can
use the same module to calculate the check digit on a 13 digit upc
code but in access it doesnt work.
Here is the vba (i didnt write it but found it to use on the internet)
Option Compare Database
Function Format_Upc_String(InString As String) As String
Dim OutString As String
Dim Multiplier As Integer, Sum As Integer, i As Integer
Dim CheckDigit As Integer
'
' Initialize the sum to zero
'
Sum = 0
'
' Add up the values of digits in the odd-numbered positions
'
For i = 1 To Len(InString) Step 2
Sum = Sum + Val(Mid$(InString, i, 1))
Next i
'
' Multiply this result by 3, then add in the values of
' the digits in the even-numbered positions
'
Sum = Sum * 3
For i = 2 To Len(InString) Step 2
Sum = Sum + Val(Mid$(InString, i, 1))
Next i
'
' Now calculate the Modulo 10 check digit
'
CheckDigit = Sum Mod 10
CheckDigit = 10 - CheckDigit
If CheckDigit = 10 Then
CheckDigit = 0
End If
OutString = InString + Format$(CheckDigit)
Format_Upc_String = OutString
End Function
Any help would be great!
check digit (using mod 10) of an 11 digit upc number. In excel i can
use the same module to calculate the check digit on a 13 digit upc
code but in access it doesnt work.
Here is the vba (i didnt write it but found it to use on the internet)
Option Compare Database
Function Format_Upc_String(InString As String) As String
Dim OutString As String
Dim Multiplier As Integer, Sum As Integer, i As Integer
Dim CheckDigit As Integer
'
' Initialize the sum to zero
'
Sum = 0
'
' Add up the values of digits in the odd-numbered positions
'
For i = 1 To Len(InString) Step 2
Sum = Sum + Val(Mid$(InString, i, 1))
Next i
'
' Multiply this result by 3, then add in the values of
' the digits in the even-numbered positions
'
Sum = Sum * 3
For i = 2 To Len(InString) Step 2
Sum = Sum + Val(Mid$(InString, i, 1))
Next i
'
' Now calculate the Modulo 10 check digit
'
CheckDigit = Sum Mod 10
CheckDigit = 10 - CheckDigit
If CheckDigit = 10 Then
CheckDigit = 0
End If
OutString = InString + Format$(CheckDigit)
Format_Upc_String = OutString
End Function
Any help would be great!