Do Loop If Statement Not Working

Bridiewms

Registered User.
Local time
Today, 20:55
Joined
Nov 4, 2013
Messages
19
I have the following code where on the load of the form which contains over 100 records I want the checkboxes to be set to false if CSCS/Insurance/passport has expired. The reason for this is even though we may enter another expiry date for the furture I want the system to flag up if we haven't got a physical copy of the new document.

The record count is working however the boxes are not being unchecked.

Private Sub Form_Load()

Dim rst As Recordset
Dim varTotal As Integer

Set rst = CurrentDb.OpenRecordset("All Personal Details", dbOpenDynaset)

' find number of records in your recordset
varTotal = Me.RecordsetClone.RecordCount
MsgBox "Number of loaded records: " & varTotal

rst.MoveFirst

' loop until run out of records
While Not rst.EOF
If [Liability_Expiry] < Now() Then
Me.[CopyofInsurance] = False
End If

If [PassportExpiry] < Now() Then
Me.[Passport] = False
End If

If [CSCS Cards].Form![CSCS Expiry] < Now() Then
Me.[CopyofCSCS] = False
End If

' moves to next record
rst.MoveNext

' one less record to go
varTotal = varTotal - 1

' start loop again
Wend

End Sub
 
What is the Form's view? Is this checkbox unbound? Why is there a need to loop through? I would suggest you explain your problem a little bit more, so a correct answer could be provided.
 
Hi,

Thank you both for your help.

I tried the Do...Loop but still no look.

I found a very simple solution to my problem. Was making things way too complicated, just needed to step back from it for a while.

Instead of unchecking the box as soon as the date expires I have created a report listing expires and then used code on the 'after update' of the date fields to uncheck the box instead, which reminds us that we need to chase up a copy of the document if we do not have one already.

Thanks again for taking the time to read the post.
 

Users who are viewing this thread

Back
Top Bottom