Having issues with getting auto update of Yes/No field dependant on todays date.
When users open the form the code runs through and checks all entries and updates the records if either of the dates in two separate fields is less than today. The issue I have is when some users are already using this form a second user cannot open it. Error shows other user information as having the form locked and code halts at highlighted spot below. Is there another way of ensuring this field is updated to Yes or No if the date in the field is less than current date.
When users open the form the code runs through and checks all entries and updates the records if either of the dates in two separate fields is less than today. The issue I have is when some users are already using this form a second user cannot open it. Error shows other user information as having the form locked and code halts at highlighted spot below. Is there another way of ensuring this field is updated to Yes or No if the date in the field is less than current date.
Code:
Private Sub Form_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("contractors")
rst.MoveFirst
Do Until rst.EOF
If rst!WorkersComp < Date Or rst!PublicLiability < Date Then
[COLOR=red]rst.Edit "Code halts here'
[/COLOR] rst!Compliant = False
rst.Update
Else
rst.Edit
rst!Compliant = True
rst.Update
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub