Microsoft Access: VBA Programming Code

Provided by Allen Browne, July 2007

Credit Card validation


This sample database (Access 2000 and later, 30kb zipped) performs check sum validation for credit cards, verifying:

It does NOT connect or obtain approval for the transaction. There is no guarantee that a valid card number is a real account, nor that there are any funds in the account. It merely catches data entry errors that could not be a valid credit card number.

To use this in your database:

  1. Import the two tables, sample form, and module into your database.
  2. Table ltCardType lists credit card types (Visa, MasterCard, etc.) Check the Inactive box for cards you do not handle.
  3. Table ltCardValid lists the valid prefix ranges, the number of digits expected for each type of card, and whether to call the check sum routine.
  4. Form frmCCExample is unbound - an example of how to set up your form. Copy the code for the CardType and CardNum controls.

The code and the data (list of cards and prefixes) is from an old database, so you may need to adjust it for newer card types or prefix ranges. Just add, remove or edit the records in table ltCardValid.

The code ignores any non-digits in the card number (spaces, hyphens, etc.)

HomeIndex of tipsTop