- 使用DoCmd对象的FindRecord方法( 效率最低 ) -查找特定记录的最简单方法是为组合框创建一个事件过程,以反映通用查找过程的每个步骤。
Private Sub cboFind_AfterUpdate() Application.Echo False Me![EmployeeID].SetFocus DoCmd.FindRecord cboFind cboFind.SetFocus Application.Echo True End Sub
- 使用DoCmd对象的ApplyFilter方法( 更有效 ) -一种更有效的方法是使用筛选器直接从窗体的记录集中选择记录。 Applyfilter方法使您可以将过滤器应用于表,表单或报表,以对表或表单或报表的基础记录集中的记录进行限制或排序。 您可以使用filtername参数将保存的查询指定为Filter,也可以在wherecondition参数中输入SQL Where子句。
Private Sub cboFind_AfterUpdate() Dim strSQL As String strSQL = "[EmployeeID] = " & Me![cboFind] DoCmd.ApplyFilter wherecondition:= strSQL End Sub
- 使用RecordsetClone( 最有效 ) -这种方法是最有效的,并且使用Form的RecordsetClone来引用Form的Recordset。
Private Sub cboFind_AfterUpdate() Dim strCriteria As String Dim rst As DAO.Recordset Set rst = Me.RecordsetClone strCriteria = "[EmployeeID] = " & Me![cboFind] rst.FindFirst strCriteria Me.Bookmark = rst.Bookmark End Sub
From: https://bytes.com/topic/access/insights/667899-finding-specific-record-programmatically