MS Access表单中使用文本和数字的多个组合框筛选

时间:2018-11-07 07:19:34

标签: vba text combobox numbers filtering

我对MS Access还是很陌生,刚刚完成在线课程,并试图通过做一个小项目来提高自己的技能。

我遇到了一个障碍,最近几天无法解决该问题。

我有一个雇员列表,其中包含诸如雇员ID,名字,姓氏,角色,职级,部门和轮班等信息。 我创建了5个组合框来过滤列表,每个组合框都与其他组合框相关。 除了一个数位的一个等级,它们都可以正常工作。

我确定这与以下事实有关:应该以某种方式将其捕获为Integer,但不知道如何链接它。

据我了解,我应该将一个变量创建为整数并将其添加到代码中,对吗? 应该如何链接?

下面是代码示例。我将不胜感激,并提供有关应如何修复的示例。

Private Sub GradeFilt_GotFocus()
   Me.AllowEdits = True
   If Nz(FiltStr, "") = "" Then
      Me.GradeFilt.RowSource = "SELECT DISTINCT Employees.Grade FROM Employees;"
   Else
      Me.GradeFilt.RowSource = "SELECT DISTINCT Employees.Grade FROM Employees WHERE" & FiltStr & ";"
   End If
   Me.GradeFilt.Dropdown
End Sub

Private Sub GradeFilt_LostFocus()
   Me.AllowEdits = False
End Sub



Sub BuildFiltStr()
   FiltStr = ""
   If Me!NameFilt <> "" Then
      FiltStr = "[LastName] = '" & Me!NameFilt & "'"
   End If
   If Me!RoleFilt <> "" Then
      If FiltStr = "" Then
         FiltStr = "[Role] = '" & Me!RoleFilt & "'"
      Else
         FiltStr = FiltStr & " AND [Role] = '" & Me!RoleFilt & "'"
      End If
   End If
   If Me!GradeFilt <> "" Then
      If FiltStr = "" Then
         FiltStr = "[Grade] = '" & Me!GradeFilt & "'"
      Else
         FiltStr = FiltStr & " AND [Grade] = '" & Me!GradeFilt & "'"
      End If
   End If
   If Me!DeptFilt <> "" Then
      If FiltStr = "" Then
         FiltStr = "[Dept] = '" & Me!DeptFilt & "'"
      Else
         FiltStr = FiltStr & " AND [Dept] = '" & Me!DeptFilt & "'"
      End If
   End If
   If Me!ShiftFilt <> "" Then
      If FiltStr = "" Then
         FiltStr = "[Shift] = '" & Me!ShiftFilt & "'"
      Else
         FiltStr = FiltStr & " AND [Shift] = '" & Me!ShiftFilt & "'"
      End If
   End If
   If FiltStr = "" Then
      Me.Filter = ""
      Me.FilterOn = False
   Else
      Me.Filter = FiltStr
      Me.FilterOn = True
   End If
End Sub

非常感谢!

0 个答案:

没有答案