Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query by form, date bug?? 1

Status
Not open for further replies.

orionsong

Programmer
May 8, 2000
34
MY
I tried to use a form as a query. Using date as the criteria. You can re-create this problem using northwind.mdb by creating two forms. I am using MS Access 97&nbsp;&nbsp;SR-2<br><br><br>Problem :<br><br>Using date, it produces wrong data, or only some of the records.<br><br>To reproduce the error, I will use the Northwind database as example. We will create 2 forms; frmProb to act as filter and frmResult to see the result of the filter action. frmResult is bound to EMPLOYEES table.<br>&nbsp;<br><br>Reproduce the error : <br><br>1.&nbsp;&nbsp;create an unbound form named frmProb<br> create 2 textbox <br> name them fromdate and todate<br> Format : medium date<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;create a&nbsp;&nbsp;command button<br> name : cmdFind<br> caption : Find<br> Event Procedure : On Click&nbsp;&nbsp;&nbsp; <br><br> Private Sub cmdFind_Click()<br> Dim strWhere As String<br> On Error GoTo Err_cmdFind_Click<br>&nbsp;&nbsp;&nbsp; strWhere = (&quot;[HireDate] Between #&quot; & Me!fromdate & &quot;# AND #&quot; & Me!todate & &quot;#&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; DoCmd.OpenForm &quot;frmResult&quot;, WhereCondition:=strWhere<br>&nbsp;&nbsp;<br> Exit_cmdFind_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br><br> Err_cmdFind_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp; MsgBox Err.Description<br>&nbsp;&nbsp;&nbsp;&nbsp; Resume Exit_cmdFind_Click<br>&nbsp;&nbsp;&nbsp;&nbsp;<br> End Sub<br><br><br>2. create a form called frmResult<br>&nbsp;&nbsp;&nbsp;&nbsp;Record Source = Employees<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;From Field List, <br>&nbsp;&nbsp;&nbsp;&nbsp;add employee ID, firstname and lastname, and hiredate to the detail<br><br>3. Close both forms.<br><br>4. Run frmProb, enter 1 March 1992 in fromdate. Enter 1 December 1992 in todate. <br>5. Click Find. The result is not correct.<br><br> <br>There is also wrong output when:<br>1) Values entered in both fromdate and todate are&nbsp;&nbsp;between 1-4 of any month of same year<br> Example : Fromdate = 1 March 1992 and Todate = 4 September 1992<br> the correct result should be 3 records, but the result here is 1 record.<br> Employees table show that there are 3 people hired from April to August.<br><br>I think there would be incorrect output by other combination as well.<br><br>There is correct output when<br>1) Value entered in todate is 5 and above, any month, same year<br>2) value entered in todate has different year from fromdate<br><br><br>Please help.....<br><br><br><br><br><br><br><br>
 
I'm getting the correct results...Leverling, Davolia, and Fuller for both criteria,&nbsp;&nbsp;I copied your code for the click direct from your post.&nbsp;&nbsp;This may sound stupid, but you <i>are</i> looking at the record counter at the bottom if you're in single-form view, and not expecting all records to show at once?&nbsp;&nbsp;&nbsp;Other than that, I can't see what could be the problem...those 3 are the only hires in '92, and all fit within both criteria.&nbsp;&nbsp;I'm using access 97 sr1.<br>--Jim
 
Thanks Jim for letting me know. <br><br>When i entered 1 March 1992 to 1 December 1992, i am getting nobody as the answer. <br><br>When i enter 1 April 1992 to 4 June 1992, my result is only Janet Leverling. <br><br>Also, i plead innocent of just looking at the record counter. Therefore, what can the problem be? Is it only me?<br>Thanks again Jim. <br><br>Anyone else who has this problem?
 
MS Access 97&nbsp;&nbsp;SR-2<br><br>Congratulations to JimHorton for being voted TipMaster of the Week.<br><br>After reading JimHorton's reply, i poked around and i found out that it is because of the setting in 'Regional Settings' that i am getting these irregular/erroneous results. My regional setting is English(United Kingdom) which is different from JimHorton's which i presume is English(United States). Therefore, you can re-create the erroneous results that i am seeing by changing your: <br><br>Control Panel&gt;Regional Settings&gt;Regional Settings tab&gt; English(United Kingdom)<br><br>You can change back to your original settings after that. <br><br>Now, what do we go about to do from here? It is a major inconvenience and probably against company policy, if i were to ask the company to change every PC in the network's regional settings to United States. After all, my company is in the UK and other applications are dependant on the current settings.<br><br>Would this issue produce wrong results in other Microsoft Office applications? Does Microsoft Office 2000 have the same issue? Is Microsoft Works in the same dilemma? What about regional settings for other countries?<br><br>
 
The UK date format is DD/MM/YYYY, where the US format is MM/DD/YYYY.&nbsp;&nbsp;&nbsp;Access is incorrectly positioning the mm and dd in the me!to/from-date clause--it looks like the short term solution is to force a format in the me!to/fromdate clause.<br><br>Observations in the debug window (UK settings):<br>?cdbl(#1/8/92#)<br>&nbsp;33611&nbsp;&nbsp;&lt;--Wrong, this is Jan 8, but UK should show Aug 1st, or 33817<br>?cdbl(#8-jan-92#)<br>&nbsp;33611 &lt;--Correct, <br>?cdbl(#jan-8-92#)<br>33611 &lt;--Correct also<br><br><br>-Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top