Link to home
Start Free TrialLog in
Avatar of jbakestull
jbakestull

asked on

Access 2007 Updated table (loop)

I have a table called tblChronicallyHomelessCombine with the following fields.
Client
Entry Date
Exit Date
Length

I need VBA code that would loop through the table and update Length as ([entry date]-[exit date]).

I tried looking for an example but not having much luck.
Avatar of jbakestull
jbakestull

ASKER

I've tried

Public Function Test()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

 
Set db = CurrentDb()
strSQL = "SELECT * FROM tblChronicallyHomelessCombine"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With rst
   Do Until rst.EOF
      .MoveFirst
      .Edit
      !Length = Date
      .Update
   

Loop
End With
 End Function

But the code keeps running.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
correction in the codes


With rst

     .MoveFirst

   Do Until .EOF
'      .MoveFirst  remove from this location
      .Edit
      !Length = DateDiff("d", ![Exit Date],![Entry Date])

      .Update
   
     .movenext  ' add this line
Loop
End With