Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Credit Card Numbers

Status
Not open for further replies.

Adams

Technical User
Mar 10, 2001
44
0
0
US
I have Credit Card Numbers in my database. When I am sending out a report I would like to mask the numbers, picking up the first two letters (VI/MC/DC/TP) and the last 4 digits and putting XXXXXXX in the middle. The length varies between 12 & 18 characters. Example:
VIXXXXXXXXXX1111
Does someone have a code that will provide this mask?

 
Hi,

Code:
sOut = Left(CC,2) & Mid("XXXXXXXXXXXX", Len(CC)-6) & Right(CC,4)


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
oops
Code:
= LEFT(CC,2) & LEFT("XXXXXXXXXXXX", LEN(CC)-6) & RIGHT(CC,4)


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Adams,

Here you go...

Paste this code into a new module.

Code:
Function fFormatCC(strCC As String) As String
'Returns: formatted Credit Card Number
'Useage: ?fFormatCC("6011000050002215")
'Returned Value:     DCxxxxxxxxxx2215

Dim intLength As Integer        'String Length
Dim intXcount As Integer        'Number of x's to use
Dim strFormattedCC As String    'Formatted String
Dim strCardType As String       'Card Type
  intLength = Len(strCC)
  intXcount = intLength - 6     'CC Length - (CardType + Last 4 digits)
  strCardType = Left(strCC, 1)
  
  Select Case strCardType
    Case 3
    If intLength <> 12 Then
    GoTo CC_ERROR
    Else
      strFormattedCC = "TP"
    End If
    Case 4
    If intLength <> 16 Then
    GoTo CC_ERROR
    Else
      strFormattedCC = "VI"
    End If
    Case 5
    If intLength <> 16 Then
    GoTo CC_ERROR
    Else
      strFormattedCC = "MC"
    End If
    Case 6
        If intLength <> 16 Then
    GoTo CC_ERROR
    Else
      strFormattedCC = "DC"
    End If
    Case Else
      GoTo CC_ERROR
  End Select
'Add the x's
Do Until intXcount = 0
  strFormattedCC = strFormattedCC & "x"
  intXcount = intXcount - 1
Loop
'Add the last 4 digits
strFormattedCC = strFormattedCC & Right(strCC, 4)
'Return the formatted string
fFormatCC = strFormattedCC

Exit Function

CC_ERROR:
MsgBox "Invalid Card Number, exiting routine.", vbCritical, "Invalid Card #"

End Function

Modify as needed.

To call from the form or report..

your out variable = fFormatCC(""YourCC"")
Single Quotes my work also, depending on your variable.
Should get you in the right direction.

You might want to check your counts...
VI,MC,DC have 16 characters if your not storing spaces or dashes.
AE I believe is 13 characters, we don't except it, I just added it in, and I don't know what TP is representing.



AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
I am having problems with this code. The format of the Credit Card number is DC11111111111111. Does the code pull the two letter Credit Card and counts the Credit Card number?
 
Code:
It seemed that your database cc number already contained the 2-character code...
Function CCMask(cc As String) As String
   CCMask = Left(cc, 2) & Left("XXXXXXXXXXXXXXXXXXXX", Len(cc) - 6) & Right(cc, 4)
End Function
/code]


Skip,
[sub]
[glasses] [b][red]Be advised:[/red][/b]  It's been reported that a wee psychic is roaming the countryside.
[b]Small Medium @ Large![/b] [tongue][/sub]
 
SkipVought, your 'be advised' messages make me cringe, laugh, cry, and want to gut myself all at the same time :p

- RoppeTech
 

The credit card mask works great. The one I am using is
FOP: Left([mpfop],2) & Left("XXXXXXXXXXXX",Len([MPFOP])-6) & Right([MPFOP],4)

but there is one problem, sometime the client pays by Check and this is coded in the Credit Card Field. When this happens the code will error out. I have tried to add another argument to the field and then I receive an error that I have the wrong number of arguments.

I have tried the code that AccessGuruCarl sent and I received errors.
 
you'll have to use an if statement to only use this function in the event its a CC and not a check or any other form of payment.

Skip,
[sub]
[glasses] [red]Be advised:[/red] It's been reported that a wee psychic is roaming the countryside.
Small Medium @ Large! [tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top