Hi I have this loop in the on Load event of my form and its not behaving as I would like, it updates the first record, but doesn't update the remaining records
Start Code:
Option Compare Database
Private Sub Form_Load()
Dim StartDate As Date
Dim RefresherDate As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Open the database and recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM qryHealthSafetyMatrixFireSafetyFireWarden")
' Check if the recordset contains any records
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst ' Move to the first record
Do Until rs.EOF
StartDate = Me![txtStartDate].Value
RefresherDate = DateAdd("yyyy", 3, StartDate)
Me![txtRefresherDate].Value = RefresherDate
MsgBox "RefresherDate"
' Move to the next record
rs.MoveNext
Loop
Else
MsgBox "No records found."
End If
' Clean up
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
End Code
I have put in a message box to confirm it is looping through, but it doesn't show the date I'm expecting to show in the message box which would then populate the fields with the required date.
I've attached some screen shots, which might help
Any suggestions on what might be wrong with what I have done would be appreciated.
Start Code:
Option Compare Database
Private Sub Form_Load()
Dim StartDate As Date
Dim RefresherDate As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Open the database and recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM qryHealthSafetyMatrixFireSafetyFireWarden")
' Check if the recordset contains any records
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst ' Move to the first record
Do Until rs.EOF
StartDate = Me![txtStartDate].Value
RefresherDate = DateAdd("yyyy", 3, StartDate)
Me![txtRefresherDate].Value = RefresherDate
MsgBox "RefresherDate"
' Move to the next record
rs.MoveNext
Loop
Else
MsgBox "No records found."
End If
' Clean up
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
End Code
I have put in a message box to confirm it is looping through, but it doesn't show the date I'm expecting to show in the message box which would then populate the fields with the required date.
I've attached some screen shots, which might help
Any suggestions on what might be wrong with what I have done would be appreciated.