Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Calculate a Credit Card Expiration Date


View products that this article applies to.

Summary

If you type a credit card expiration date (month/year) in a Date/Time field on a form, Microsoft Access 2000 assumes that the card expires on the first day of the month. This article shows you how to create a function to correctly calculate the expiration date as the last day of the month.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To make a credit card expiration date the last day of the month entered, follow these steps:
  1. Start Microsoft Access and open a new database.
  2. Create a new table and add the following fields:
    Field Name: CardNumber
    Data Type: Text

    Field Name: Expiration
    Data Type: Date/Time

    Field Name: Name
    Data Type: Text
    Save the table as Cards, and then close it.

  3. Create a new module with the following function:
    Option Explicit
    Function ExpirationDay (MyDate as Control)
    
       Dim NextMonth
       If IsNull(MyDate) Then Exit Function
       NextMonth = DateAdd("m", 1, MyDate)
       MyDate = NextMonth - DatePart("d", NextMonth)
    
    End Function
    					
  4. Create a new form based on the Cards table using the AutoForm: Columnar option. On the View menu, click Design View.
  5. Click the Expiration text box and set its AfterUpdate property to the following expression:
    =ExpirationDay([Expiration])
  6. On the View menu, click Form View. Type 04/2000 in the Expiration text box, and then press the TAB key.
Notice that the date changes to "30-Apr-00," the last day of the fourth month of the year 2000. You can also use the following derivative of the ExpirationDay() function in calculated fields in a query:
Function ExpirationDay (MyDate)
    Dim NextMonth
    If IsNull(MyDate) Then Exit Function
    NextMonth = DateAdd("m", 1, MyDate)
    ExpirationDay = NextMonth - DatePart("d", NextMonth)
End Function
				

↑ Back to the top


Keywords: KB210534, kbprogramming, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 210534
Revision : 3
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 352