I see it:
Public Function TidyMyData() As Boolean
Const MyTable As String = "Query2"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(MyTable)
Dim strID As String
Dim strSQl As String
Dim intCountID As Integer
Dim intCountChecks As Integer
With rs
Do While Not .EOF
If strID <> .Fields(.Fields(0).Name) Then
strID = .Fields(.Fields(0).Name)
End If
intCountID = DCount("TableID", MyTable, "TableID = """ & strID & """")
intCountChecks = DCount("Test", MyTable, "Test = True And TableID = """ & strID & """")
If intCountID > 3 Then
If intCountChecks < 3 Then
.Edit
.Fields("Test") = True
.Update
End If
Else
.Edit
.Fields("Test") = True
.Update
End If
.MoveNext
Loop
.Close
End With
db.Close
strSQl = "DELETE * FROM " & MyTable & " WHERE Test = False;"
DoCmd.RunSQL strSQl
Set rs = Nothing
Set db = Nothing
End Function
Stewart J. McAbney |
Talk History