473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FindFirst and query not finding records - date values

I wrote some code that creates a table with a date/time field at
15-minute intervals. Here's how I create and populate the table

With tblDataTemp

..Fields.Append .CreateField("CT_ID", dbLong)
..Fields.Append .CreateField(strTmpIDFld, dbLong)
..Fields.Append .CreateField(strTmpDateFld, dbDate)
..Fields.Append .CreateField(strTmpDataFld, dbDouble)

End With
..
..
..
dtAdd = AdjustTime(dtStart)
Do While dtAdd < dtEnd + 1 + 15 / 1440
rstDataTemp.AddNew
rstDataTemp.Fields(strTmpDateFld).Value = dtAdd
rstDataTemp.Update
dtAdd = dtAdd + 15 / 1440
Loop

I then use the FindFirst method to search for a record with a specific
date/time. Here is that line in the code:

rstDataTemp.FindFirst ("[" & strTmpDateFld & "]" & "=#" + strAdjDate +
"#")

The problem is, it only works for times up to 4/18/2005 15:30 (this
happens to be the first 3 records, but I have tried deleting those
first 3 records and then it finds nothing). I have stopped the code,
copied and pasted the value of strAdjDate into a query, and it doesn't
find the record. I have even copied and pasted a value directly from
the table I created into the criteria of the query builder and it
*still* doesn't return the record.

I have some similar code that creates records with date/time (but one
at a time, it reads the dates from another table then writes to this
table), and I use a FindFirst on that and it works fine:

rstData.FindFirst ("[" & strDateFld & "]" & "=#" + theAdjDate + "# AND
[" & strIDFld & "] = " & Trim(Str(numID)))

So I'm thinking it has to do wtih the way I'm creating the table in the
first place?? Anyone have any idea?

Thanks
Rebecca

Nov 13 '05 #1
2 3105
This problem is an example of the impresicion of floating point numbers.

The Date/Time data type in access is stored as a real number, where the
integer part represents the date and the fractional part the time of day:
0.5 = noon; 0.25 = 6am, and so on. Unfortunately, binary numbers (and even
decimal numbers) cannot represent the times precisely. It is very common to
not get exact matches, and if you add fractions in a loop the approach
doomed.

You could use an integer loop controller to avoid the increasing error,
e.g.:
For i = 0 to 95
rstDataTemp.AddNew
rstDataTemp.Fields(strTmpDateFld) = DateAdd("m", i * 15, dtStart)
rstDataTemp.Update
Next

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ri**********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I wrote some code that creates a table with a date/time field at
15-minute intervals. Here's how I create and populate the table

With tblDataTemp

.Fields.Append .CreateField("CT_ID", dbLong)
.Fields.Append .CreateField(strTmpIDFld, dbLong)
.Fields.Append .CreateField(strTmpDateFld, dbDate)
.Fields.Append .CreateField(strTmpDataFld, dbDouble)

End With
.
.
.
dtAdd = AdjustTime(dtStart)
Do While dtAdd < dtEnd + 1 + 15 / 1440
rstDataTemp.AddNew
rstDataTemp.Fields(strTmpDateFld).Value = dtAdd
rstDataTemp.Update
dtAdd = dtAdd + 15 / 1440
Loop

I then use the FindFirst method to search for a record with a specific
date/time. Here is that line in the code:

rstDataTemp.FindFirst ("[" & strTmpDateFld & "]" & "=#" + strAdjDate +
"#")

The problem is, it only works for times up to 4/18/2005 15:30 (this
happens to be the first 3 records, but I have tried deleting those
first 3 records and then it finds nothing). I have stopped the code,
copied and pasted the value of strAdjDate into a query, and it doesn't
find the record. I have even copied and pasted a value directly from
the table I created into the criteria of the query builder and it
*still* doesn't return the record.

I have some similar code that creates records with date/time (but one
at a time, it reads the dates from another table then writes to this
table), and I use a FindFirst on that and it works fine:

rstData.FindFirst ("[" & strDateFld & "]" & "=#" + theAdjDate + "# AND
[" & strIDFld & "] = " & Trim(Str(numID)))

So I'm thinking it has to do wtih the way I'm creating the table in the
first place?? Anyone have any idea?

Thanks
Rebecca

Nov 13 '05 #2
Allen,
That worked better than what I was doing. However, it did not work for
every 3rd record. I'm not sure why, but probably with some fiddling I
could have gotten it to work.

But what I did instead is I added records with dates as I needed to -
ie I read from my import table, and if the date did not exist in the
table I was creating, I added a record. I should have done this from
the beginning, but I thought it would be easier to work with a table
where the records were already populated with dates.

Thanks for your help.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DBNovice | last post by:
I have a database that keeps records on the issue and failure of an item. Currently, the database is poorly desisned; therefore I'm performing queries to break the data into normalized tables and...
3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
5
by: Mike | last post by:
Hi I've written a module to find the first occurrence of a record in a query (that is my forms datasource) that matches four specified criteria. No matter what I try it doesn't seem to find ...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
2
by: keri | last post by:
Hi everyone, I'm using findfirst in code as below. It searches a query that shows appointment date and account name and should return the account name of the first appointment on each day into...
4
by: Rick | last post by:
Access2003 in XP I'm using the code below to append any new records from (tbl_From_Mainframe) into (tbl_Appended_Data). It takes more than a minute to search 7000 records for a dozen new records....
4
by: dizzydangler | last post by:
Hi all, I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.