ACC2002: How to Force Access to Display Dates with Four-Digit Years (286453)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q286453
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 214701.

SUMMARY

Microsoft Access has two options that force date fields and controls to display four-digit years. One option, This database, forces the display of four-digit years at the database level in a particular database or project. The other option, All databases, forces the display of four-digit years at the application level in all databases and projects.

The reason for these options is to make sure the user is aware of which century is being used. These options only affect the format of the date. Access stores dates as serial numbers. For example, when you type the date 4/16/50 (April 16, 1950), it is actually stored as the serial number 18369. The date April 16, 2050 is stored as the serial number 54894.

MORE INFORMATION

To access these two options from the user interface, click Options on the Tools menu, and then click the General tab. In the Use four-digit year formatting area, the This database check box controls the database-level option and the All databases check box controls the application-level option.

If either of these options is set, Access overrides the specified date format to show a four-digit year. The year portion of the date is the only part affected. Other parts of the date still rely on the Windows Regional Settings and Date formats.

The database-level option is stored in the Microsoft Access database (MDB) or Microsoft Access project (ADP). This allows developers to deliver Year 2000 compliant applications, regardless of the user's regional settings.

The application-level option is stored in the registry with all the other Access settings. This allows administrators to force all Access applications on the computer to use four-digit years, regardless of regional settings, date formats, or the database-level option.

You can programmatically check or set these options with the GetOption and SetOption methods, respectively.

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. The following segment of code returns the current database-level setting:
If GetOption("Four-Digit Year Formatting") = True Then
    MsgBox "This database is using four-digit year formatting."
Else
    MsgBox "This database is not using four-digit year formatting."
End If
				
The following segment of code forces Access to use four-digit year formatting at the database-level:
SetOption "Four-Digit Year Formatting", True
				
The following segment of code returns the current application-level setting:
If GetOption("Four-Digit Year Formatting All Databases") = True Then
    MsgBox "Access is using four-digit year formatting."
Else
    MsgBox "Access is not using four-digit year formatting."
End If
				
The following segment of code forces Access to use four-digit year formatting at the application-level:
SetOption "Four-Digit Year Formatting All Databases", True
				

REFERENCES

For more information about the GetOption and SetOption methods, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type getoption, setoption methods in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdta kbhowto KB286453