Bookmark Error

D

Doctor

I use this code below to open a form in dialog mode, make changes, and on
close requery the calling form and go to the record that I was on. I use this
book mark code all the time. But this time I am getting an error. My code and
the error are below.

The calling form is based on a query.

Thanks in advance.


Dim stDocName As String
Dim stLinkCriteria As String
Dim vBook As Variant

stDocName = "LLCRegistrations"
vBook = Me.Bookmark


stLinkCriteria = "[LLRegID]=" & Me![LLRegID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog

Me.Requery

If Not IsEmpty(vBook) Then
Me.Bookmark = vBook
End If


Error: 3159.
Not a valid bookmark.
 
A

Allen Browne

When you requery the form, its recordset is loaded again. Consequently the
bookmark saved previously is invalid.

You need to save the primary key value, and FindFirst in the form's
RecordsetClone after the Requery. This kind of thing:

Dim rs As DAO.Recordset
Dim varID As Variant
If Me.Dirty Then Me.Dirty = False 'Save any edits.
varID = Me.LLRegID
'open your form and do your stuff here.
Me.Requery
Set rs = Me.RecordsetClone
If IsNull(varID) Then 'Must have been the new record.
RunCommand acCmdRecordsGotoNew
Else 'Find the record again.
rs.FindFirst "LLRegID = " & varID
If rs.NoMatch Then
MsgBox varID & " has gone."
Else
Me.Bookmark = rs.Bookmark
End If
End If
Set rs = Nothing

Note that we used a Variant to hold the ID value, as it can be Null (at a
new record.)
 
D

Doctor

Thanks so much!

Allen Browne said:
When you requery the form, its recordset is loaded again. Consequently the
bookmark saved previously is invalid.

You need to save the primary key value, and FindFirst in the form's
RecordsetClone after the Requery. This kind of thing:

Dim rs As DAO.Recordset
Dim varID As Variant
If Me.Dirty Then Me.Dirty = False 'Save any edits.
varID = Me.LLRegID
'open your form and do your stuff here.
Me.Requery
Set rs = Me.RecordsetClone
If IsNull(varID) Then 'Must have been the new record.
RunCommand acCmdRecordsGotoNew
Else 'Find the record again.
rs.FindFirst "LLRegID = " & varID
If rs.NoMatch Then
MsgBox varID & " has gone."
Else
Me.Bookmark = rs.Bookmark
End If
End If
Set rs = Nothing

Note that we used a Variant to hold the ID value, as it can be Null (at a
new record.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Doctor said:
I use this code below to open a form in dialog mode, make changes, and on
close requery the calling form and go to the record that I was on. I use
this
book mark code all the time. But this time I am getting an error. My code
and
the error are below.

The calling form is based on a query.

Thanks in advance.


Dim stDocName As String
Dim stLinkCriteria As String
Dim vBook As Variant

stDocName = "LLCRegistrations"
vBook = Me.Bookmark


stLinkCriteria = "[LLRegID]=" & Me![LLRegID]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog

Me.Requery

If Not IsEmpty(vBook) Then
Me.Bookmark = vBook
End If


Error: 3159.
Not a valid bookmark.
 

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