DAO Empty Recordset "No Current Record"

J

John

I'm trying to use DAO to pre-create records on a form to an empty updateable
recordset. Later the user will fill in one value field in each record.
(My KeyField uses a defaultvalue of =NZ(DMax("[DefectID]","tblDefects"),0)+1
to generate a key value)

Private Sub cmdSetup_Click()
Dim Rst As DAO.Recordset
Set Rst = Form.RecordsetClone
Rst.AddNew
Rst.Edit
Rst("LengthM") = 100
Rst.Update
End Sub

I've tried, .MoveFirst, .AddNew, but they generate an "No Current Record"
error.

How can I get to that first new record to Edit and Update with my values?

Thanks,
John
 
G

Graham Mandeno

Hi John

Delete the line that says Rst.Edit.

The Edit method is for modifying *existing* records. AddNew adds a new
record *and* puts it in a state for editing.
 
J

John

Graham,
Thanks a lot. Works like a champ!
Found a lot of associated hits on this in the Google groups, but no one laid
it out quite so clearly.
John

Graham Mandeno said:
Hi John

Delete the line that says Rst.Edit.

The Edit method is for modifying *existing* records. AddNew adds a new
record *and* puts it in a state for editing.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

John said:
I'm trying to use DAO to pre-create records on a form to an empty
updateable recordset. Later the user will fill in one value field in
each record. (My KeyField uses a defaultvalue of
=NZ(DMax("[DefectID]","tblDefects"),0)+1 to generate a key value)

Private Sub cmdSetup_Click()
Dim Rst As DAO.Recordset
Set Rst = Form.RecordsetClone
Rst.AddNew
Rst.Edit
Rst("LengthM") = 100
Rst.Update
End Sub

I've tried, .MoveFirst, .AddNew, but they generate an "No Current Record"
error.

How can I get to that first new record to Edit and Update with my values?

Thanks,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top