【发布时间】:2021-02-03 09:26:59
【问题描述】:
我对 Access 和 VBA 都很陌生。我创建了一个搜索按钮,根据在不同组合框中选择的内容查找不同的项目。但是,我想添加另一个搜索条件,如果我在名为“txtNotes”的文本框中键入文本,我可以在“tbl_ContructionOrders”表中的名为“Notes”的表字段中查找看起来像匹配项的记录。匹配必须有点松散,因为每个人输入的注释都不同,并且希望使用此框来查找我们遇到类似问题的工作订单,并且可能有更简单的方法找到解决上述问题的方法。
这是我目前所拥有的,但它不起作用
Private Sub btnLookup_Click()
Dim strWhere As String
Me.Filter = True
strWhere = ""
If IsNull(Me.txtNotes) Then
If Not IsNull(Me.txtNotes) Then
If strWhere <> "" Then
strWhere = strWhere & " like [Notes] = """ & Me.txtNotes & """"
Else
strWhere = strWhere & "[Notes] = """ & Me.txtNotes & """"
End If
End If
If Len(strWhere) <= 0 Then
MsgBox "No Criteria", vbInformation, "No Input."
Else
Me.Filter = strWhere
Me.FilterOn = True
Me.Requery
End If
If Me.FilterOn Then
If Me.Recordset.RecordCount = 0 Then
MsgBox "Nothing Found."
End If
End If
End Sub
【问题讨论】:
-
您要搜索还是过滤?
-
我想过滤与我在文本框中输入的内容有些匹配的记录
标签: vba ms-access ms-access-2010