好的,在網上找不到關於此錯誤的任何信息,所以在這裏。無法更新。數據庫或對象在Requery之後是隻讀的
使用Access 2003.我有一個窗體有一個組合框下拉框。用戶從下拉列表中選擇,VBA代碼查看特定的表格以查看數據是否已經存在。如果找到它,它會顯示與記錄關聯的數據。如果沒有找到它,它會向表中添加一條新記錄,然後嘗試顯示新數據。問題是,使用下面的代碼時,它不會顯示新的數據,除非我添加Me.Requery。但是,如果我這樣做,那麼如果我再次嘗試執行相同的過程,則會給我上述錯誤。
那麼,在沒有上述錯誤的情況下如何才能在添加數據後顯示數據呢?
下面是相關代碼...
' Find the record that matches the control.
Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
'if no record found, then add a default record
If IsNull(Combo119) Then
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [Master Reject Data]")
rs.AddNew
rs.Fields("production Date") = Date
rs.Fields("Work Order #") = Combo119.Column(0)
rs.Fields("Product Type") = ""
rs.Fields("Shift") = ""
rs.Fields("Line") = ""
rs.Fields("# Produced") = 0
rs.Fields("Reject Type") = ""
rs.Fields("Reject Quantity") = 0
rs.Fields("Reject Category") = "Rejection"
Dim tRec As Long
tRec = Combo142.ItemData(0)
rs.Fields("Report Number") = tRec
rs.Update
Me.Requery 'this is the line I added to try to get the data to appear
Set rs = Me.Recordset.Clone
rs.FindFirst "[Report Number] = " & tRec 'navigate to the newly added record
Else
rs.FindFirst "[Report Number] = " & Nz(Me![Combo119], 0) 'navigate to the record with the requested report number
End If
If Not rs.EOF Then Me.Bookmark = rs.Bookmark