我有一个带有多个复选框的访问连续表单,其中三个复选框分配给周三,周四,周五的特定日期。您可以选择三天中的一天或没有意味着您还没有做出选择。我试图循环并计算每天的复选框数量来计算。复选框链接到我的SQL表中的字段。但到目前为止,它只计算所有记录而不是我需要的记录。代码如下......
Sub getRecordCount()
Dim rst As Recordset
Dim dba As Database
Dim strSQL As String
Dim Site As String
Dim i As Integer
Site = Nz(DLookup("[Site]", "Locaton", "[LOC_ID] = Forms.frmUtility![Site].value"), "")
Set dba = CurrentDb
If Site <> "" Then
strSQL = "SELECT * FROM dbo_" & Site & "_Employees"
Else
strSQL = "SELECT * FROM dbo_tbl_Employees"
End If
Set rst = dba.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
With rst
.MoveLast
.MoveFirst
While Not rst.EOF
If Me.Wednesday = True Or Me.Thursday = True Or Me.Friday = True Then
i = i + 1
End If
rst.MoveNext
Wend
End With
MsgBox i
End Sub