我正在嘗試在我的表格的列表框控件中搜索當前選定的項目。如何在DAO數據庫中正確使用搜索
在更新事件之後,我的列表框控件,我有這樣的代碼
Private Sub lst_MainList_AfterUpdate()
Dim theDB As DAO.Database
Dim theProposalsTable As DAO.Recordset
Set theDB = CurrentDb
Set theProposalsTable = theDB.OpenRecordset("tbl_PROPOSAL", dbOpenDynaset)
theSeeker theProposalsTable, Me.lst_PPpg_MainList.Value
End Sub
然後,我有一子在我模塊1與此代碼。我得到這個從示例代碼@https://msdn.microsoft.com/en-us/library/office/ff836416.aspx
Sub theSeeker(ByRef rstTemp As Recordset, intSeek As Integer)
Dim theBookmark As Variant
Dim theMessage As String
With rstTemp
' Store current record location.
theBookmark = .Bookmark
.Seek "=", intSeek
' If Seek method fails, notify user and return to the
' last current record.
If .NoMatch Then
theMessage = "Not found! Returning to current record." & vbCr & vbCr & "NoMatch = " & .NoMatch
MsgBox theMessage
.Bookmark = theBookmark
End If
End With
End Sub
我得到運行時錯誤是不支持這種類型的對象3251操作。
點擊調試時,它突出.Seek "=", intSeek
我得到運行時錯誤3219當我使用'dbOpenTable'無效操作。我正在使用訪問2016年,以防萬一它是關聯訪問表 – Wayne
。我的前端與我的數據分開。數據存儲在一個訪問文件中。前端使用鏈接表管理器訪問它,但都是訪問數據庫而不是SQL數據庫。如果我的設置是鏈接表,還有什麼可以用來搜索記錄?會發現第一次工作? – Wayne
是的,'FindFirst'應該可以工作。它不需要「表格型記錄集」。 – HansUp