3159 "Not a valid bookmark" after AddNew & LastModified

G

GDW

I receive the 3159 error when the following code hits the line noted by
"->".

Set rs = frmCommand.Recordset

With rs
.AddNew
' .Update
-> frmCommand.Bookmark = .LastModified
End With

I tried inserting "Update" after "AddNew" as I had seen in code
examples elsewhere but the empty record violated constraints and
couldn't be updated. "LastModified" appears to have no value (viewed
in Watch window) after the "AddNew" statement. I thought that
"LastModified" was supposed to represent both new and updated records.

Any ideas?

Thanks,
Gary
 
G

GDW

I implemented a workaround for this problem but am still interested in
why this is not working as I would have expected and what other people
do to handle the situation.

My workaround was to the following sub in the frmCommand definition:

Public Sub AddNew()
DoCmd.GoToRecord , , acNewRec
End Sub

Works fine.

Gary
 
A

Allen Browne

How are frmCommand and rs declared?

If frmCommand is a Form variable, and rs is disambuguiated as from the DAO
library, it should work if you do something like this:

Dim frmCommand As Form
Dim rs As DAO.Recordset
Set frm = Forms("SomeFormNameHere")
Set rs = frmCommand.RecordsetClone
With rs
.AddNew
'Assign field values here.
.Update
frmCommand.Bookmark = .LastModified
End With
Set rs = Nothing
Set frmCommand = Nothing

The RecordsetClone has been around much longer, and seems to be more
reliable.
 
G

GDW

Thanks for the response Allen.

rs is declared as a DAO.RecordSet and frmCommand as a Form. I tried
setting rs to both frmCommand.RecordSet and frmCommand.RecordSetClone.

The problem with your example as I explained in my original email is
that I don't want to assign values to certain fields and the lack of
values in those fields violates constraints and therefore causes an
error upon execution of the Update statement.

I'm guessing that a new record doesn't actually get added to the
RecordSet after AddNew until you perform the Update and that's the
reason that LastModified won't work in my case.

Gary
 

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