如何解决在Access中使用文本框进行VBA搜索
我对Access和VBA都很陌生。我创建了一个搜索按钮,该按钮根据在不同组合框中选择的内容查找不同的项目。但是,我想添加另一个搜索条件,如果我在名为“ txtNotes”的texBox中键入文本,则可以在“ 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
解决方法
尝试一下:
Private Sub Command0_Click()
'empty notes
If IsNull(txtNotes.Value) Then
MsgBox "No Criteria",vbInformation,"No Input."
Exit Sub
End If
'search
Filter = "[Notes] Like '*" & txtNotes.Value & "*'"
FilterOn = True
'count records
If RecordsetClone.RecordCount = 0 Then
MsgBox "Nothing Found."
FilterOn = False
End If
End Sub
如果您想在键入时进行搜索(过滤),请使用以下命令:
Private Sub txtNotes_Change()
'search after x number of chars
If Len(txtNotes.Text) <= 3 Then
FilterOn = False
Filter = vbNullString
Else
Filter = "[Notes] Like '*" & txtNotes.Text & "*'"
FilterOn = True
End If
End Sub
,
听起来您想要一个自动完成的对象。突出显示要在表格中自动填充的单词。使用窗体上的组合框控件选择单词。这是一个指导性视频,向您展示如何进行设置。
https://www.youtube.com/watch?v=ptRb8ffv4f0
如果您需要其他东西,请发回。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。