我在表格上有一个qdf作为记录源的数据表。
我想提供从同一表单上的文本框中搜索通配字符串的第一个/下一个出现(行)的数据表中的特定列的功能(例如,使用MfgID跳转到NEXT RECORD,如 123 )。
我不是真的在寻找一个过滤器,因为我需要在周围记录的上下文中看到匹配的记录。
有关如何开始的任何建议吗?
答案 0 :(得分:3)
感谢HansUp的指针。这是我实施的内容:
1. Sets focus to the desired column
2. Supports multiple btn clicks, to keep looking for the NEXT occurence
3. When no_match or end of list, returns to first record, clears txtSearch
--------------
Private Sub btnSearch_Click()
Dim rs As Object
On error goto err_handler
Forms![myForm]![mySubform].Form![MFGID].SetFocus
Set rs = Forms![myForm]![mySubform].Form.RecordsetClone
rs.FindNext "[MfgID] like '*" & Me![txtSearch] & "*'"
If Not Trim(Me![txtSearch]) = "" Then
Forms![myForm]![mySubform].Form.Bookmark = rs.Bookmark
Else
MsgBox "Please enter search criteria.", vbOKOnly, "Error"
Me![txtSearch].SetFocus
Exit Sub
End If
If Not rs.NoMatch Then
Forms![myForm]![mySubform].Form.Bookmark = rs.Bookmark
Else
MsgBox "Match not found for: " & Me![txtSearch] & "", , "Error"
rs.MoveFirst
Forms![myForm]![mySubform].Form.Bookmark = rs.Bookmark
Me![txtSearch] = ""
End If
err_exit:
Exit Sub
err_handler:
If Err.Number = 2455 Then GoTo err_exit
MsgBox Err.Number
exit sub