I had someone enter the initial records into a form and the dates were set as default to =Now(). This is fine for normal data entry but the dates should have been set to an earlier date for 400+ records that were initially entered. I have some code that loops through all records in a table and checks that a transaction date is greater then a certain date. If it is greater it should set the date to the "corrected" date but this is not working.
The code is looping from record zero to EOF. The looping works fine and the absolute record position increments but from the watches window, the textfield Me.DateStockTrx shows the correct date the first time through the loop but subsequent times through the loop this text field shows the date that the first record was changed to. Me.DateStockTrx does not match what is in the field of the recordset. The field of the recordset is correct. So the if then statement is never true after the first pass through the loop.
Here is the code:
Code:
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim Int1 As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select * from Inventory;")
Int1 = 0
With rs
If Not (.EOF Or .BOF) Then
rs.MoveFirst
Do Until .EOF
.Edit
If (Format(Me!dateStockTrx, "m/dd/yyyy") > #8/15/2012#) Then
Me!dateStockTrx = #7/28/2012#
End If
.Update
.MoveNext
Int1 = Int1 + 1
Loop
.Close
Else
End If
End With
I also tried the following:
Code:
Dim rs As Object
Dim Int1 As Integer
Set rs = Me.Recordset.Clone
Int1 = 0
With rs
If Not (.EOF Or .BOF) Then
rs.MoveFirst
Do Until .EOF
.Edit
If (Format(Me!dateStockTrx, "m/dd/yyyy") > #8/15/2012#) Then
Me!dateStockTrx = #7/28/2012#
End If
.Update
.MoveNext
Int1 = Int1 + 1
Loop
.Close
Else
End If
End With