Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Bookmark Error

Geek News

Bookmark Error
Doctor 11/11/2008 12:32:01 AM
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.
Re: Bookmark Error
"Allen Browne" <AllenBrowne[ at ]SeeSig.Invalid> 11/11/2008 6:59:59 AM
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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Doctor" <Doctor[ at ]discussions.microsoft.com> wrote in message
news:7F6E19B4-C2CA-48F9-8F5F-7D0D8768E51B[ at ]microsoft.com...
[Quoted Text]
>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.

Re: Bookmark Error
Doctor 11/11/2008 4:43:02 PM
Thanks so much!

"Allen Browne" wrote:

[Quoted Text]
> 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
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Doctor" <Doctor[ at ]discussions.microsoft.com> wrote in message
> news:7F6E19B4-C2CA-48F9-8F5F-7D0D8768E51B[ at ]microsoft.com...
> >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.
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net