Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 无法更新。数据库或对象在重新查询后为只读_Ms Access_Vba - Fatal编程技术网

Ms access 无法更新。数据库或对象在重新查询后为只读

Ms access 无法更新。数据库或对象在重新查询后为只读,ms-access,vba,Ms Access,Vba,好的,在网上找不到关于这个错误的任何信息,所以现在开始 使用Access 2003。我有一个表单,它有一个组合框下拉列表。用户从下拉列表中进行选择,VBA代码查看特定的表以查看数据是否已经存在。如果找到它,它将显示与记录关联的数据。如果找不到,它会向表中添加一条新记录,然后尝试显示新数据。问题是,当使用以下代码时,它不会显示新数据,除非我添加了Me.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

抱歉,再次查看后发现问题。问题是Me.Requery语句必须是Me.Recordset.Requery。执行此操作并添加Me.Refresh后,它将按预期工作。

为了避免重新查询,我认为您应该打开记录集,指定它应该是动态集
CurrentDb.OpenRecordset(“从[Master Reject Data]中选择*”,dbOpenDynaset)
-以防您想让它更整洁一点。至于小虫子,我看你已经找到了自己