Microsoft KB Archive/210534

= ACC2000: How to Calculate a Credit Card Expiration Date =

Article ID: 210534

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210534



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).



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.



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:  Start Microsoft Access and open a new database. 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.

  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  Create a new form based on the Cards table using the AutoForm: Columnar option. On the View menu, click Design View. Click the Expiration text box and set its AfterUpdate property to the following expression:

=ExpirationDay([Expiration])

 On the View menu, click Form View. Type 04/2000 in the Expiration text box, and then press the TAB key.</li></ol>

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

Additional query words: date

Keywords: kbhowto kbinfo kbprogramming KB210534

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.