By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

Looping through recordset only returns first record each time - not the next an so on

P: 4
Here is the problematic code:
Expand|Select|Wrap|Line Numbers
  1. Dim rst1 As DAO.Recordset
  2. Set rst1 = CurrentDb.OpenRecordset("SETimes", dbOpenDynaset)
  3.     With rst1
  4.         Do While Not .EOF
  5.         CurSDate = rst.Fields("STimes").Valuet
  6.         MsgBox(CurSDate)
  7.         CurSDateUK = CurSDate
  8.         CurSDateV = DateAdd("s", -60, CurSDateUK)
  9.         CurSDateVF = Format(Left([CurSDateV], 10), "yyyy-mm-dd")
  10.         CurSTimeVF = Right(CurSDateV, 8)
  11.         CurSDateV = CurSDateVF & " " & CurSTimeVF
  12.         CurFSDate = Format(Left(CurSDate, 10), "yyyy-mm-dd")
  13.         CurFSTime = Right(CurSDate, 8)
  14.         CurSDate = CurFSDate & " " & CurFSTime
  15.         CurEDate = rst.Fields("ETimes").Value
  16.         CurEDateUK = CurEDate
  17.         CurFEDate = Format(Left(CurEDate, 10), "yyyy-mm-dd")
  18.         CurFETime = Right(CurEDate, 8)
  19.         CurEDate = CurFEDate & " " & CurFETime
  20.  
So basically, I have a table SETimes, which contains (this varies) but around 13 start dates and 13 end dates.
The previous loop I have in the code above this section works fine, but with this, it loops through until it reaches the end of the recordset (13 loops), but defines the 'CurSDate' variable as being the first record each time. I added a message box to demonstrate this, but I do not understand what is going on here. The table which the recordset opens has 13 different dates, each on their own numbered row - plus the same code seems to work earlier in the sequence.
Am I missing something here?

Thanks in advance,
-Craig
Dec 13 '11 #1

✓ answered by ADezii

  1. Is the following a Typo?
    Expand|Select|Wrap|Line Numbers
    1. CurSDate = rst.Fields("STimes").Valuet 
  2. Your Code is cut off, but I do not see an explicit .MoveNext in order to advance through the Loop.

Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,616
  1. Is the following a Typo?
    Expand|Select|Wrap|Line Numbers
    1. CurSDate = rst.Fields("STimes").Valuet 
  2. Your Code is cut off, but I do not see an explicit .MoveNext in order to advance through the Loop.
Dec 13 '11 #2

P: 4
Yes it was a typo, and also I was referencing rst for the record source variable instead of rst2!
Thanks for the help bro!
-Craig
Dec 13 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.