Error Update without Addnew or Edit

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

I am getting the following 3020 error after updating to
AC2000

Update without Addnew or Edit

The code is below

Any help is welcome

Thanks


Set db = CurrentDb
Set RstDoc = db.OpenRecordset("R-Approb",
Set rstdis = db.OpenRecordset("R-DistributionMAJ",
dbOpenDynaset, 0, dbOptimistic)
searSt = "[NomDoc] = " & "'" & Trim(Forms("ModifDoc")!
DocCherche) & "'"
RstDoc.MoveFirst
RstDoc.FindFirst (searSt)
If Not RstDoc.NoMatch Then

rstdis.AddNew
rstdis.Bookmark = rstdis.LastModified
rstdis.Fields("POSTE") = "0000"
rstdis.Fields("GQ0501_r02") = "X"
rstdis.Fields("Groupe") = RstDoc.Fields("Groupe")
rstdis.Fields("Zone") = RstDoc.Fields("Zone")
rstdis.Fields("Point") = RstDoc.Fields("Point")
rstdis.Fields("Element") = RstDoc.Fields("Element")
rstdis.Fields("Ext") = RstDoc.Fields("Ext")
rstdis.Fields("Edit") = RstDoc.Fields("Edit")
rstdis.Fields("Rev") = RstDoc.Fields("Rev")
rstdis.Fields("Page") = RstDoc.Fields("Page")
If GlobalApprobation Then
rstdis.Fields("Date_Emis") = RstDoc.Fields
("Date_Appr")
Else
rstdis.Fields("Date_Emis") = RstDoc.Fields
("Date_Emis")
End If
rstdis.Fields("EOREC") = RstDoc.Fields("EOREC")
rstdis.Update
rstdis.Close
 
Seems that by removing the statement
rstdis.Bookmark = rstdis.LastModified
It solved the problem.
Does not know why ??
 
Seems that by removing the statement
rstdis.Bookmark = rstdis.LastModified
It solved the problem.
Does not know why ??

That statement will attempt to reposition the recordset to another
record than the one you're working on. Therefore, the new record you
began with .AddNew is discarded. Following that, you proceed with a
bunch of field assignments -- without first calling the .Edit method --
and then call .Update. But on *this* record, no .AddNew or .Edit method
call has been made. So the error message is accurate.
 
Thanks this is clearer now.
The strange thing is that this was working in Access 97 !!

I've looked into it, and it seems to be a difference in the version of
either DAO or Jet. In both cases, record movement doesn't actually take
place in the code you posted, because there is no LastModified record in
this newly opened recordset. But in Access 97, the line
rstdis.Bookmark = rstdis.LastModified

(when there is no rstdis.LastModified) seems not to cancel the .AddNew,
while in Access 2002 (and probably Access 2000), it does. Note this
caution, which appears in the DAO help files for both versions:

Caution If you issue an AddNew and then perform any
operation that moves to another record, but without using
Update, your changes are lost without warning. In addition,
if you close the Recordset or end the procedure that declares
the Recordset or its Database object, the new record is
discarded without warning.

So the two versions seem to handle the failure of the Bookmark
assignment differently. A2002, it appears, cancels the AddNew first,
while A97 cancels it only after the recordset is actually repositioned.

You'll find, by the way, that if you first modify a record in the
recordset (so that there is a .LastModified record) then call .AddNew,
set .Bookmark = .LastModified, and then try to modify a field's value,
you'll get the error message even in Access 97.
 
Back
Top