好的,在网上找不到有关此错误的任何信息,所以就到这里。
使用 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