Harold said:
Using XP and trying to validate the various credit cards
on a form. I've seen through another Access program that
if the number is not a valid number, it'll tell you right
away.
Here's some code posted in an Access newsgroup several years ago. I
personally have not checked it for accuracy, nor do I have the name of
whomever posted it:
Validating a Credit Card Number The following function will return true or
false depending whether or not a credit card is valid.
NOTE: This code will only tell you if the number entered is valid for a
credit card, not if the actual card itself is valid.
Function CheckCard(CCNumber As String) As Boolean
Dim Counter As Integer, TmpInt As Integer
Dim Answer As Integer
Counter = 1
TmpInt = 0
While Counter <= Len(CCNumber)
If IsEven(Len(CCNumber)) Then
TmpInt = Val(Mid$(CCNumber, Counter, 1))
If Not IsEven(Counter) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
Else
TmpInt = Val(Mid$(CCNumber, Counter, 1))
If IsEven(Counter) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
End If
Wend
Answer = Answer Mod 10
If Answer = 0 Then CheckCard = True
End Function
Function IsEven ( plngValue As Long ) As Boolean
IsEven = ((plngValue MOD 2) = 0)
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access