R
Rob Parker
I have the following section of code (and several other similar ones, which
all work fine):
Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryInspAccess_Current")
qdf.Parameters("[CardID]") = Me.InspCardID
Set rst = qdf.OpenRecordset(, dbOpenForwardOnly)
Set rstSub = dbs.OpenRecordset("RWOP_DAT_InspAccess", dbOpenDynaset,
dbAppendOnly)
Do Until rst.EOF
rstSub.AddNew
rstSub!AccessID = rst!AccessItemID
rstSub!InspectionID = Me.InspID
rstSub.Update
rst.MoveNext
Loop
The problem is that the .AddNew statement generates error 3022 (changes not
successful, duplicate values ...). The problem is that the new record in
rstSub is being generated using an existing number for the InspAccessID, an
autonumber field in RWOP_DAT_InspAccess.
I get the same problem if I open the RWOP_DAT_InspAccess query and try to
add a new record in the query - it shows an existing autonumber field, and
fails with the same error message. I get the same problem if I try to add a
new record directly in the linked table which is the basis of the RWOP
query. And finally, I get the same problem if I try to add a new record
directly into the table in the back-end .mbd file. I've run a
compact/repair on that file, but it's had no effect. How can I fix this?
And, to prevent possible future recurrence of this, what could have caused
it?
TIA,
Rob
all work fine):
Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryInspAccess_Current")
qdf.Parameters("[CardID]") = Me.InspCardID
Set rst = qdf.OpenRecordset(, dbOpenForwardOnly)
Set rstSub = dbs.OpenRecordset("RWOP_DAT_InspAccess", dbOpenDynaset,
dbAppendOnly)
Do Until rst.EOF
rstSub.AddNew
rstSub!AccessID = rst!AccessItemID
rstSub!InspectionID = Me.InspID
rstSub.Update
rst.MoveNext
Loop
The problem is that the .AddNew statement generates error 3022 (changes not
successful, duplicate values ...). The problem is that the new record in
rstSub is being generated using an existing number for the InspAccessID, an
autonumber field in RWOP_DAT_InspAccess.
I get the same problem if I open the RWOP_DAT_InspAccess query and try to
add a new record in the query - it shows an existing autonumber field, and
fails with the same error message. I get the same problem if I try to add a
new record directly in the linked table which is the basis of the RWOP
query. And finally, I get the same problem if I try to add a new record
directly into the table in the back-end .mbd file. I've run a
compact/repair on that file, but it's had no effect. How can I fix this?
And, to prevent possible future recurrence of this, what could have caused
it?
TIA,
Rob