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)
5310

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

如果要搜索是單箇值,可以用《access組閤框篩選綁定窗體的記録》方法

但是很多情況下,多箇值作爲(wèi)查找條件會(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,因爲(wèi)牠允許使用更複雜的條件,併且不需要設(shè)置被搜索的控件爲(wèi)可見。也不需要將光標(biāo)定位到某箇控件上卽可使用。

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

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