我有一个包含员工信息表的访问数据库。我的问题是我想遍历另一个表,以便首先确定特定特征是真还是假,然后以连续形式显示所有为真的记录。它仍然填充所有记录,而不仅仅是真实的记录。请看下面的代码。
Private Sub RunQuery_Click()
Dim strSQL As String
Dim dba As Database
Dim tbl As Recordset
Dim Code As String
Dim status As String
Set dba = CurrentDb
strSQL = "SELECT DISTINCT EmployeeName,SSN,Location,SystemAssignedPersonID FROM dbo_tbl_Random "
strSQL = strSQL & "WHERE MenuUsed = 'Random' ORDER BY Location,EmployeeName"
Set tbl = dba.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
With tbl
.MoveFirst
If tbl.EOF Then
MsgBox "There are no employees on Random at this time.", , "Oops! Try Again"
Else
Do Until tbl.EOF
status = getEmpStatusID(tbl!SystemAssignedPersonID)
If status = "A" Then
Set Me.Recordset = tbl
.MoveNext
Else
.MoveNext
End If
Loop
End If
End With
Set tbl = Nothing
Set dba = Nothing
End Sub
getEmpStatusID 是一个单独的函数,不会给我带来麻烦。它查找员工 ID 以获取信息并正常返回。
谢谢您的帮助!