A2007 ADO Update

  • Thread starter Thread starter JimS
  • Start date Start date
J

JimS

I have a form that uses a class module to insert rows into a table. The class
(clsPicklist) is properly instantiated, opens 4 ADO recordsets, then proceeds
to add the first row to the table just fine. When it goes to add the second
record, it finds a duplicate key (as it should), and goes to update the
quantity rather than adding a new row. At this point, it gets an error
indicating that the record "may have been modified since it was last read",
and fails. Any ideas what I'm doing wrong?

Herewith the relevant code:

(Initialize time...)
rstPickListDetail.Open "tblPickListDetail", cnn, adOpenDynamic,
adLockOptimistic
..
..
..
(part of the AddDetail method...)
Public Function AddNewDetail(BoMDetailID As Long, Quantity As Double) As Long
..
..
..
With rstPickListDetail
.Filter = "PLPicklistID=" & m_lngPicklistID
.Find "PLBoMDetailID=" & BoMDetailID, , adSearchForward, 1
If .EOF Then
.AddNew
!PLPicklistID = m_lngPicklistID
!PLBoMDetailID = BoMDetailID
!PLDetailQtytoPick = Quantity
Else
!PLDetailQtytoPick = !PLDetailQtytoPick + Quantity
End If
.Update
AddNewDetail = !PLDetailID
.Filter = adFilterNone
End With
..
..
..
 
On Mon, 21 Dec 2009 08:37:01 -0800, JimS

Not sure. Your code looks decent, except for the .Filter line which is
not needed. Comment it out. I might replace it with a .MoveFirst line.

-Tom.
Microsoft Access MVP
 
Back
Top