473,734 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("C T_ID", dbLong)
..Fields.Append .CreateField(st rTmpIDFld, dbLong)
..Fields.Append .CreateField(st rTmpDateFld, dbDate)
..Fields.Append .CreateField(st rTmpDataFld, dbDouble)

End With
..
..
..
dtAdd = AdjustTime(dtSt art)
Do While dtAdd < dtEnd + 1 + 15 / 1440
rstDataTemp.Add New
rstDataTemp.Fie lds(strTmpDateF ld).Value = dtAdd
rstDataTemp.Upd ate
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.Fin dFirst ("[" & 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.FindFir st ("[" & 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 3166
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.Add New
rstDataTemp.Fie lds(strTmpDateF ld) = DateAdd("m", i * 15, dtStart)
rstDataTemp.Upd ate
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**********@g mail.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.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("C T_ID", dbLong)
.Fields.Append .CreateField(st rTmpIDFld, dbLong)
.Fields.Append .CreateField(st rTmpDateFld, dbDate)
.Fields.Append .CreateField(st rTmpDataFld, dbDouble)

End With
.
.
.
dtAdd = AdjustTime(dtSt art)
Do While dtAdd < dtEnd + 1 + 15 / 1440
rstDataTemp.Add New
rstDataTemp.Fie lds(strTmpDateF ld).Value = dtAdd
rstDataTemp.Upd ate
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.Fin dFirst ("[" & 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.FindFir st ("[" & 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
2976
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 attempting to perform a "left join" query to build a cross-reference table. The left join query is currently taking nearly 2 hours for MySQL to process, using Navicat as a front-end. My system specs are 1.4Mhz Pentium Processor with 1GB of RAM...
3
4985
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 and 90. The default is set at 30. Question1: When the form opens, there are no records displayed although there are many records that fit the criteria of 30. If I put a button on the form to do a requery and press the button, all the records...
5
4387
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 records even though they are in the recordset as you can navigate to them using the forms navigation buttons. weekending, weekday, ba (business area), projected Here's the module can anyone spot where i'm going wrong? Any suggestions would be...
1
2914
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 2000. The access file is in access 2000 format. I have a form that will hold the relevent parameters for the query/report that reports the statistics for all job records that match a certain criteria. These are: - A Customer Name.
24
19910
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 renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes with every renewal Renewals in 2004 would be D, 2005 S, and 2006 L. polexpdates for a given customer...
2
5738
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 icluding the selected date or all records on or after the selected date The user selects either "=", >=" or "<=" from a combo box and then a date from another combobox. The combination of thse two choices is then set in an unbound textbox so...
2
2456
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 the same date in a calendar form. If rs.RecordCount 0 Then For i = 1 To 37 If IsDate(f("date" & i)) Then
4
5240
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. The file I'm searching is in a data farm so I'm stuck with using it in its present format. Linking to the file or importing it as a local table have no effect on speed. How can I get this code to perform quicker?
4
9497
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 the process of migrating the data over to Access 2007 (Windows XP), kind of learning as I go. I’ve managed to import the client records into a single table, and set up a “single view” form that streamlines how we input new client data. Now I’m...
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.