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!

Add an input mask for varying credit card formats (MC/V/AMEX)

Status
Not open for further replies.

ajaeger

Technical User
Feb 6, 2003
201
0
0
US
I'm not sure how to go about this. I have to enter credit card numbers into an Access database. They can be AmEx, MC, Visa or Discover. I'd like to create an input mask so it's easier to enter/view. However, the formats are different. For AmEx, the format is ####-######-##### (4-6-5). For the others it's ####-####-####-#### (4-4-4-4). Is there a way to create a mask that looks at the first number entered and formats the mask based on that? For example, if the user enters a 4, it knows that is should apply the VISA mask. If a 5, the MC mask. If a 3, the AmEx mask. And if a 6, the Discover mask.

If not, another alternative is that I could have the user indicate the credit card type in field 1 and then enter the credit card number in field 2. Can I get the mask formating of field 2 to read the value in field 1 and apply the appropriate mask?

Also, if anyone can confirm the format (4-4-4-4) and starting number for Discover card, I'd appreciate it. I can't seem to find anyone who has a Discover card...

Thanks!

Anna Jaeger
iMIS Database Support
 
I think you will have to have the user enter the Card type first and then set your mask from there. In the AfterUpdate Event for the Card type, you can use something like this

If Me.CardTypeTextbox = "AmEx" Then
Me.CardNumberTextbox.InputMask = "####-######-#####"
Else
Me.CardNumberTextbox.InputMask = "####-####-####-####"
End If

This should do what you need.
If my wife gets up, I'll get the format for Discover[wink]


Paul
 
Thanks Paul. That works pretty well. One thing that is a little funny is that the mask changes if I go to the next record and it requires a different format.

My form displays about a dozen different rows. Each row is a different record. If the user enters A (for Amex) in the CC_TYPE field on record 1, when they enter the first number in the CC_NUM field, the appropriate ####-######-##### mask appears. However, when they tab to the next record and enter V (for VISA) in the CC_TYPE field of record 2, the mask for record 1 changes. Instead of showing ####-######-#####, it uses the MC/VISA/DISC mask of ####-####-####-### (only 3 numbers in the last set since Amex is 15 digits while the others are 16). Similarly, if I then enter a CC_TYPE of A, it tries to reformat all of the CC_NUMs to the AmEx format. Since it can't fit the 16 digits for MC/VISA/DISC into the 15 digit AmEx format, it doesn't apply any mask.

Is there a way to specify that I want the mask to apply only to that particular record. I may need a different mask for the next record.

Thanks.

Anna Jaeger
iMIS Database Support
 
Bummer. I'm sorry, I didn't look further into this. Here's what I did. I added a second CardNumber textbox named AmEx. I renamed the other textbox AllOthers. Then I set the Control Source for both textboxes to the CardNumber field so that everything would be entered into the Table. Then I put the two textboxes on top of each other and used this code in the AfterUpdate Event for the CardType box(I left the visible property for both boxes set to Yes):

Code:
Private Sub CardType_AfterUpdate()
If Me.CardType = "AmEx" Then
Me.AmEx.Visible = True
Me.AllOthers.Visible = False
Me.AmEx.SetFocus
Me.AmEx.InputMask = "####\-######\-#####"
Else
Me.AllOthers.Visible = True
Me.AmEx.Visible = False
Me.AllOthers.SetFocus
Me.AllOthers.InputMask = "####\-####\-####\-####"
End If
End Sub

And this code in the Current Event for the Form.

Code:
Private Sub Form_Current()
If Me.CardType = "AmEx" Then
Me.AmEx.Visible = True
Me.AllOthers.Visible = False
Me.AmEx.InputMask = "####\-######\-#####"
Else
Me.AllOthers.Visible = True
Me.AmEx.Visible = False
Me.AllOthers.InputMask = "####\-####\-####\-####"
End If
End Sub

It shows the values the way you want. The only problem I found was that it didn't store the values in the table with any dashes (-). Not sure why but try it out and post back with problems.

Paul
 
My Discover starts with a 6 and is a 4-4-4-4 format.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top