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!

Very odd Loop problem

Status
Not open for further replies.

PRMiller

Technical User
Mar 18, 2004
95
US
I have the following code set up in my database:



Dim dDate As Date
Dim sCurrentTime As String
Dim sEventTime As String

dDate = Date + 1
sTime = "03:00:00 AM"
sEventTime = dDate & " " & sTime

Do Until sCurrentTime > sEventTime
sCurrentTime = FormatDateTime(Now(), vbGeneralDate)
Loop

blahblahblah


What is supposed to happen (and did happen until today) was that the code would run a continuous loop until tomorrow's date at 03:00:01 AM. For example, if executed today, sEventTime = "08/10/2004 03:00:00 AM", and sCurrentTime continues to reset, beginning with "08/09/2004 7:53:30 PM" or whatever.

For some reason, VBA assumes the loop has met this argument and goes on to execute the next line of code (symbolized by the blahblah line). In debug mode, both sEventTime and sCurrentTime are populating correctly, yet it thinks the argument has been met. I checked our system date, but that shouldn't matter, since the code always sets to execute at the system date + 1.

This is a very strange problem... any thoughts?

Thanks,
Paul
 
P.S. I also have dimmed "sTime As String
 
Have you tried something like this ?
sEventTime = Format(1 + Date() + TimeSerial(3, 0, 0), "yyyymmddhhnnss")
Do
sCurrentTime = Format(Now(), "yyyymmddhhnnss")
Loop Until sCurrentTime > sEventTime


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Have you tried something like this ?
sEventTime = Format(1 + Date() + TimeSerial(3, 0, 0), "yyyymmddhhnnss")
Do
sCurrentTime = Format(Now(), "yyyymmddhhnnss")
DoEvents
Loop Until sCurrentTime > sEventTime


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

The problem seems to have corrected istelf. The code functions as normally, and I made no modfications. Very strange!

Thanks for the suggestion, though.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top