我打算编写一个代码,从Employees列表框中选择员工,并将其添加到指定的列表中。我有两个列表框,其中一个是根据项目编号填充的,右边一个显示所有员工。当我使用任何过滤器时,员工列表框(右侧)变得无法选择,我无法定义我想要管理的员工。到目前为止,我使用了这段代码:
Private Sub FilterEmployees()
Dim strListSource As String
strListSource = "SELECT tblLU_Employee.EmployeeID, StrConv([tblLU_Employee].[FirstName],3) AS [First Name], StrConv([tblLU_Employee].[LastName],3) AS [Last Name] FROM tblLU_Employee"
If CityFilt = "" And StatusFilt = "" Then
'no change
ElseIf CityFilt <> "" And StatusFilt <> "" Then
strListSource = strListSource & " WHERE tblLU_Employee.Office = '" & CityFilt.Value & "'"
strListSource = strListSource & " AND tblLU_Employee.Status = '" & StatusFilt & "'"
ElseIf CityFilt <> "" Then
strListSource = strListSource & " WHERE tblLU_Employee.Office = '" & CityFilt.Value & "'"
ElseIf StatusFilt <> "" Then
strListSource = strListSource & " WHERE tblLU_Employee.Status = '" & StatusFilt & "'"
End If
strListSource = strListSource & " ORDER BY tblLU_Employee.LastName"
NonAssignedList.RowSource = strListSource
Me.AllowEdits = True
NonAssignedList.AllowValueListEdits = True
如果我不使用过滤器,我可以选择我想要的员工,但如果我使用过滤器我就不能。请检查图像:
答案 0 :(得分:0)
有些事情值得尝试:
NonAssignedList.Requery
查询:
SELECT tblLU_Employee.EmployeeID, StrConv([tblLU_Employee].[FirstName],3) AS [First Name],
StrConv([tblLU_Employee].[LastName],3) AS [Last Name] FROM tblLU_Employee
WHERE
iif(ISNULL(Forms!YourFormNameHere!CityFilt), 1=1,
tblLU_Employee.Office = "'" & Forms!YourFormNameHere!CityFilt & "'")
AND
iif(ISNULL(Forms!YourFormNameHere!StatusFilt), 1=1,
tblLU_Employee.Status = "'" & Forms!YourFormNameHere!StatusFilt & "'")
然后,只要过滤器下拉列表中的任何一个随NonassignedList.Requery
变化,就可以触发重新查询