Gustav Brock
Gustav at cactus.dk
Wed Jan 23 10:13:06 CST 2008
Hi Mark When they match and you stop the loop, do a Debug.Print CDbl(RecordDT), CDbl(RecordDT_end), CDbl(RecordDT - RecordDT_end) and I guess you'll see why. /gustav >>> markamatte at hotmail.com 23-01-2008 17:05:10 >>> Hello All, Thanks for the suggestions. I found last night that "DateDiff("s", RecordDT, RecordDT_end) = 0" would work...but I just can't seem to understand why they were not equal. I tried the suggestion below...but it failed as well. I also tried "If RecordDT>= RecordDT_end"...this works...but scares me because I don't know why it works and "=" does not. I think I will just use the datediff approach...but am still curious... Thanks, Mark A. Matte > Date: Wed, 23 Jan 2008 10:17:35 +0100 > From: Gustav at cactus.dk > To: accessd at databaseadvisors.com > Subject: Re: [AccessD] Loop Until Date=Date > > Hi Mark > > Your problem is perhaps that you are casting the poor date time values to and from string values. > > Try this: > > ' Remove a time part and add new time. > RecordDT_end = Fix(rst!Q_DT.Value) + #4:30:00 PM# > RecordDT = Fix(rst!Q_DT.Value) + #9:30:00 AM#) > > Do Until RecordDT = RecordDT_end > If RecordDT = RecordDT_end Then MsgBox "yes" > 'Inner Loop > RecordDT = DateAdd("n", 30, RecordDT) > Loop > > If that still fails, follow the advice from Andy to eliminate rounding errors: > > Do Until DateDiff("s", RecordDT, RecordDT_end) = 0 > > /gustav > > >>>> markamatte at hotmail.com 23-01-2008 01:05:13>>> > > Hello All, > > I am looping thru a recordset...and I need it to stop when it gets to a certain time. I am sure I am missing something simple...below is the code...it FAILS!!!...and I have no clue why...probably very simple...but anyway...any thoughts...even the IF fails...when they appear to be equal???? > > > Dim RecordDT As Date > Dim RecordDT_end As Date > RecordDT_end = CDate(rst!Q_DT & " 4:30:00 PM") > RecordDT = CDate(rst!Q_DT & " 9:30:00 AM") > > Do Until RecordDT = RecordDT_end > If RecordDT = RecordDT_end Then MsgBox "yes" > 'Inner Loop > > > RecordDT = CDate(DateAdd("n", 30, RecordDT)) > Loop > > > Thanks, > > mark