B
Brian
I have a public function that does Luhn validation (verifying whether a
credit card number is of valid format). It looks something like this:
Public Function LuhnCheck(CC As String) As Boolean
Dim LuhnVal As Integer
LuhnVal = blah, blah, blah 'several lines to evalute LuhnVal as a derivative
of CC
LuhnCheck = (LuhnVal Mod 10 = 0) 'will be True or False
End Function
This correctly evaluates to True or False when called from a form so that I
can do this:
If Not LuhnCheck(CCNumber) Then
MsgBox "The card number entered has failed Luhn validation.",
vbCritical, ""
End If
I now want to call this function from within a query, thus:
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer;
This works fine, but returns LuhnCheck as -1 or 0. Any attempt to include a
WHERE clause involving the LuhnCheck result fails with "Data type mismatch in
criteria expression", as in both of these:
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer
WHERE LuhnCheck([CCNumber])=False;
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer
WHERE LuhnCheck([CCNumber])=0;
In fact, if I run the query manually (without the WHERE clause), then
attempt to manually filter either to the LuhnCheck or to exclude it, I get
the same data type mismatch error.
How can I get my function to return a usable result?
credit card number is of valid format). It looks something like this:
Public Function LuhnCheck(CC As String) As Boolean
Dim LuhnVal As Integer
LuhnVal = blah, blah, blah 'several lines to evalute LuhnVal as a derivative
of CC
LuhnCheck = (LuhnVal Mod 10 = 0) 'will be True or False
End Function
This correctly evaluates to True or False when called from a form so that I
can do this:
If Not LuhnCheck(CCNumber) Then
MsgBox "The card number entered has failed Luhn validation.",
vbCritical, ""
End If
I now want to call this function from within a query, thus:
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer;
This works fine, but returns LuhnCheck as -1 or 0. Any attempt to include a
WHERE clause involving the LuhnCheck result fails with "Data type mismatch in
criteria expression", as in both of these:
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer
WHERE LuhnCheck([CCNumber])=False;
SELECT Customer.CustomerID, LuhnCheck([CCNumber]) AS LuhnCheck
FROM Customer
WHERE LuhnCheck([CCNumber])=0;
In fact, if I run the query manually (without the WHERE clause), then
attempt to manually filter either to the LuhnCheck or to exclude it, I get
the same data type mismatch error.
How can I get my function to return a usable result?