Access VB Loop (1 Viewer)

siddhusingh1968

New member
Local time
Today, 01:54
Joined
Apr 9, 2011
Messages
7
I have this code to sequence dates in an Access db. It grabs the end date of the first record and pastes it into the start date of the next record and so forth. I need to modify this code to sequence the dates from the current record i.e. where the cursor is instead of going to the first record. I get a NULL error for the PREVDATE value when I try to do that. What am I doing wrong? Please.
***CODE****
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim PREVDATE As String ' will hold value of end date from previous record in this variable
If rst.RecordCount <> 0 Then
End If
rst.MoveFirst 'moves cursor to first record
Do
'Add code to trap t2TaskDuration null values to update to arbitrary number of 8 or so...
PREVDATE = rst.Fields("t2Plan_End")
rst.MoveNext ' test
If Not rst.EOF Then
rst.Edit
rst.Fields("t2Plan_Start") = DateAdd("d", 1, PREVDATE)
rst.Fields("t2Plan_End") = rst.Fields("t2Plan_Start") + rst.Fields("t2TaskDuration")
rst.Update
Else
Exit Do
 

pr2-eugin

Super Moderator
Local time
Today, 09:54
Joined
Nov 30, 2011
Messages
8,494
Is this the actual Code you have implemented? I could see so many syntax error and missing statements.. Try to check it again, organise it neatly..
 

siddhusingh1968

New member
Local time
Today, 01:54
Joined
Apr 9, 2011
Messages
7
This is the code I have been using.
'=========================
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim PREVDATE As String ' will hold value of end date from previous record in this variable
If rst.RecordCount <> 0 Then
End If
rst.MoveFirst 'moves cursor to first record
Do
PREVDATE = rst.Fields("End")
rst.MoveNext ' test
If Not rst.EOF Then
rst.Edit
rst.Fields("t2TestDate") = PREVDATE 'Puts value held in PREVDATE variable in start date of next record
rst.Update
Else
Exit Do
End If
MsgBox "Test End Date Loop" ' to test routine
Loop
rst.Close
End Sub
'============================
 

Users who are viewing this thread

Top Bottom