In article <rG*******************@news02.tsnz.net>,
gj <go****@google.google> wrote:
I have an application in Access 97 I will be rewriting in the latest
version of Access in 6 months. In the meantime, does anyone know of an
ActiveX control I can add into an Access 97 form to allow the validation
of Credit Card numbers and also processing of payments.
As a starter, the function below will allow you to determine whether the
credit card number is valid, according to its built-in check digit. This
works for both Visa and Mastercard.
Public Function CheckCCNum(CCNum As String) As Boolean
' Return TRUE if CCNum appears to be a valid credit card number.
Dim MyNum As String, char As String
Dim I As Integer, Sum As Integer
' Remove any non-numeric characters from CCNum.
MyNum = ""
For I = 1 To Len(CCNum)
char = Mid(CCNum, I, 1)
If char >= "0" And char <= "9" Then MyNum = MyNum & char
Next I
' Result should be an even number of digits
If Len(MyNum) = 0 Or Len(MyNum) Mod 2 = 1 Then
CheckCCNum = False
Exit Function
End If
' For each odd digit, multiply it by two, add the digits in the
product,
' then add it to the sum of the even digits.
For I = 1 To Len(MyNum) Step 2
Sum = Sum + Fix((2 * Mid(MyNum, I, 1)) / 10)
Sum = Sum + Fix((2 * Mid(MyNum, I, 1)) Mod 10)
Sum = Sum + Mid(MyNum, I + 1, 1)
Next I
' If final sum is evenly divisible by 10, the number is valid.
CheckCCNum = IIf(Sum Mod 10 = 0, True, False)
End Function
--
"Sometimes what seems to be enough smoke to guarantee a robust
fire is actually just a cloud of dust from a passing bandwagon."
- Daniel Dennett