office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

微信交流群(請(qǐng)用微信掃碼)

        

access使用書簽的方法篩選記錄

2020-02-18 08:00:00
tmtony8
原創(chuàng)
5307

查找記錄的控件顯示在窗體時(shí),F(xiàn)indRecord方法是一種非常好的搜索方式。

如果要搜索是單個(gè)值,可以用《access組合框篩選綁定窗體的記錄》方法

但是很多情況下,多個(gè)值作為查找條件會(huì)使用書簽的方法查找記錄,如下設(shè)計(jì)視圖


詳細(xì)源代碼:

Private Sub cboQuickSearch_AfterUpdate()
  
  Dim rsClone As DAO.Recordset
  Dim sCriteria As String
  
  Const sSEARCHFLD As String = "[ProductID]"
  
  If Not IsNull(Me.cboQuickSearch.Value) Then

    Set rsClone = Me.RecordsetClone
    
    ' Build the criteria:
    sCriteria = sSEARCHFLD & " = " & Me.cboQuickSearch.Value
    
    ' Perform the search:
    rsClone.FindFirst sCriteria
    
    If Not rsClone.NoMatch Then
        'Synchronize the form's bookmark
        'to the recordset's record:
        Me.Bookmark = rsClone.Bookmark
    End If
    
    rsClone.Close
    Set rsClone = Nothing
    
  End If
  
End Sub

篩選效果如圖所示


使用findFirst或者bookmark方法要好于使用findrecord,因?yàn)樗试S使用更復(fù)雜的條件,并且不需要設(shè)置被搜索的控件為可見(jiàn)。也不需要將光標(biāo)定位到某個(gè)控件上即可使用。

說(shuō)明一下,RecordsetClone屬性創(chuàng)建的記錄集是DAO類型的記錄集。只有DAO記錄集支持Findfirst、findLast、Findnext、findprevious 方法。

    分享
    文章分類
    聯(lián)系我們
    聯(lián)系人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動(dòng)訪問(wèn)