Microsoft KB Archive/295698

= ACC2002: Incorrect Records Are Selected When the Criterion Is a Date and the Short Date Format Is d/M/yy =

Article ID: 295698

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q295698



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

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



SYMPTOMS
If your computer's Regional Options (or Regional Settings) Short date format setting is set to d/M/yy, Microsoft Access may be unable to find records, or it may find incorrect records, when you use a command button on one form to open another form and display records for a specific date. This behavior does not occur when the selected date falls after the 12th day of a month, or in cases where the day and month are the same number, such as &quot;5 May&quot; or &quot;11 November.&quot;



CAUSE
This behavior can occur because, when you select a Date/Time field as the criterion for record selection, the Command Button Wizard creates an event procedure that includes code similar to the following: stLinkCriteria = &quot;[Record Date]=&quot; & &quot;#&quot; & Me![Combo0] & &quot;#&quot; DoCmd.OpenForm stDocName,, , stLinkCriteria When this code is run, the date value from the combo box or other control is interpreted as a short date in the format M/d/yy, regardless of the format chosen for the fields in question or in the Regional Options dialog box. As a result, a date such as July 10, 2000, may be represented as &quot;10/7/00&quot; in a table's data and in a combo box, but is interpreted as &quot;7/10/00,&quot; or October 7, 2000, when the command button is clicked. This may cause the wrong record, or an empty record, to be displayed in the form that is opened by the command button.



RESOLUTION
You can work around this issue through either of two methods, depending on whether the data-matching process is intended to select one specific record or a collection of records based on the selected date.

Method 1: Include the Format Function in the Selection Code
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. You can work around this issue by modifying the code produced by the Command Button Wizard so that the date is specifically presented in Medium Date format, which is interpreted correctly for all dates.

For an example of how to do this, follow these steps after performing the steps in the &quot;Steps to Reproduce the Problem&quot; section of this article:  Open the form Test Form in Design view. Right-click the command button, and then click Build Event on the shortcut menu.  Revise the following line stLinkCriteria = &quot;[Record Date] = &quot; & &quot;#&quot; & Me![Combo0] & &quot;#&quot; to the following: stLinkCriteria = &quot;[Record Date] = &quot; & &quot;#&quot; & Format(Me![Combo0],&quot;Medium Date&quot;) & &quot;#&quot; 

For more information about the Format function, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type named date/time formats (format function) in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Method 2: Use a Separate Key Field to Select One Specific Record
If the date field uniquely identifies a particular record, as in the preceding sample code, you can work around this behavior by adding an AutoNumber field to the table as its primary key and using the key value in the record selection. Then, re-create the controls that provide the lookup information and open the second form.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The Command Button Wizard enables you to create a command button on one form that opens a second form that displays only those records that match specific data identified on the first form. If the matching data are of the Date/Time type, the computer's Short date format setting influences the matching process and can lead to the selection of incorrect records.

The Short date format setting of M/d/yy is common in the United States, and represents the date October 7, 2000 as &quot;10/7/00.&quot; In other parts of the world, including the United Kingdom and Commonwealth countries, the same date is often represented as &quot;7/10/00&quot; -- that is, in a Short date format setting of d/M/yy. While d/M/yy is not a listed option under Short date format, it can be set by a user with Administrator privileges. If that has been done, Access may not return the correct records when forms are opened, as illustrated in the &quot;Steps to Reproduce the Problem&quot; section.

When the Short date format setting is M/d/yy, all the records are displayed as expected. However, when the Short date format setting is d/M/yy, only the records for dates after the 12th of the month are selected correctly. If you select a date that is earlier than the 13th (for example, October 7, 2000, in the following sample data) you may find that the form opens to the record for an incorrect date, such as July 10, 2000, in this example, or to a new record (as though the required data does not exist) if there is no record for July 10, 2000.

Steps to Reproduce the Problem
NOTE: Because there are several versions of Microsoft Windows, the following steps may be different on your computer. If they are, see your product documentation to complete these steps.

 Click Start, point to Settings, and then click Control Panel. Double-click Regional Options (or Regional Settings in Microsoft Windows 98), and then click the Date tab. Note the setting for Short date format, and then select M/d/yy.</li> Start Access and create a new database named DateTest.mdb .</li>  Create the following table named Date List: <pre class="fixed_text">  Table: Date List Field Name: Record Date Data Type: Date/Time Indexed: Yes (No Duplicates)

Field Name: Record Note Data Type: Text

Table Properties: Date List ---  PrimaryKey: Record Date </li> Use AutoForm to create a form based on the Date List table, accepting the default name &quot;Date List&quot; for the form.</li>  Using either the form or datasheet view of the table, enter the following data, making sure that you enter the same keystrokes in the Record Note field that you used in the Record Date field to preserve a record of your data entry. <pre class="fixed_text">   Record Date        Record Note ---       ---    10 Jul 00           10 Jul 00 7 Oct 00           7 Oct 00 30 Oct 00          30 Oct 00 11 Nov 00          11 Nov 00 13 Nov 00          13 Nov 00 </li> Create a new form, not based on any table, in Design view.</li> Ensure that the Control Wizard on the Toolbox is turned on, and then place an unbound combo box on the form. In the Combo Box Wizard:  Select look up the values, and then click Next.</li> Select the table Date List, and then click Next.</li> Select all fields, and then click Next.</li> Click to clear the Hide key column check box, and then click Next.</li> Select Record Date as the bound column, and then click Finish.</li></ol> </li> Place a command button on the form, and then follow these steps in the Command Button Wizard:  Click Form Operations under Categories, click Open Form under Actions, and then click Next.</li> <li>Select the form Date List, and then click Next.</li> <li>Select Open the form and find specific data, and then click Next.</li> <li>Click Combo0 under Form1, click Record Date under Date List, and then click the match button (<->). Click Finish.</li></ol> </li> <li>Save the form as Test Form, and then open it in Form view.</li> <li>Use the combo box to select the first record, 10 Jul 00, and then click the command button to open the Date List form.

Notice whether or not the correct record is displayed. Repeat this for other dates listed in the combo box.</li> <li>Again open the Regional Options dialog box, and then select d/M/yy as the Short date format setting.

You may need Administrator privileges to make this change.</li> <li>Repeat step 10. Notice that when you select the first record (Record Note = &quot;10 Jul 00&quot;), the record displayed is the second record (Record Note = &quot;7 Oct 00&quot;).</li></ol>

Additional query words: pra prb

Keywords: kbbug KB295698

-

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

© Microsoft Corporation. All rights reserved.