Can't get bookmark to work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

After failing to get bookmarking to work, I set up a tiny little test table and then a form based on query with a simple command button with a click event. The code comes right out of several papers and Access help and is as follows

Private Sub testbookmark_Click(
Dim szbookmark As String, rst As Recordset '1 paper says DAO.recordset - no diff..fail
Set rst = Me.RecordsetClon
szbookmark = Me.Bookmark 'bookmark 1st recor
rst.MoveNext: rst.MoveNex
MsgBox "should be at record 3" 'at this point I haven't moved off of record
rst.Bookmark = szbookmark 'should go to record
rst.MoveNext 'should go to record
MsgBox "should be at record 2" 'I'm still at record on

Any idea what I'm missing here

Regards, Ro

End Sub
 
cove3 said:
After failing to get bookmarking to work, I set up a tiny little test table and then a form based on query with a simple command button with a click event. The code comes right out of several papers and Access help and is as follows:

Private Sub testbookmark_Click()
Dim szbookmark As String, rst As Recordset '1 paper says DAO.recordset - no diff..fails
Set rst = Me.RecordsetClone
szbookmark = Me.Bookmark 'bookmark 1st record
rst.MoveNext: rst.MoveNext
MsgBox "should be at record 3" 'at this point I haven't moved off of record 1
rst.Bookmark = szbookmark 'should go to record 1
rst.MoveNext 'should go to record 2
MsgBox "should be at record 2" 'I'm still at record one


The RecordsetClone object is a separate instance of the
form's recordset. While the two recordset have the same
data in the same order and share bookmark values, they have
independent active records. To sync the form's active
record to the RecordsetClone's current record, you have to
assign the bookmark from one to the other:

Set rst = Me.RecordsetClone

rst.MoveFirst 'make sure at first record

szbookmark = Me.Bookmark 'bookmark 1st ecord
rst.MoveNext: rst.MoveNext

Me.Bookmark = rst.Bookmark

MsgBox "should be at record 3"
rst.Bookmark = szbookmark
rst.MoveNext

Me.Bookmark = rst.Bookmark

MsgBox "should be at record 2"
 
Thanks Jim. Works like a charm. But now I'm wondering why I even need a shadow/clone instance. Can't I just do:
szbookmark=me.bookmark
docmd.gotorecord , , next
me!bookmark = szbookmark

This saves the bookmark for record 1, goes to record 2, and then goes back to record 1. What is the purpose of even going through rst.movenext, or anything having to do with a recordsetclone?

Regards, Ron



The RecordsetClone object is a separate instance of the
form's recordset. While the two recordset have the same
data in the same order and share bookmark values, they have
independent active records. To sync the form's active
record to the RecordsetClone's current record, you have to
assign the bookmark from one to the other:

Set rst = Me.RecordsetClone

rst.MoveFirst 'make sure at first record

szbookmark = Me.Bookmark 'bookmark 1st ecord
rst.MoveNext: rst.MoveNext

Me.Bookmark = rst.Bookmark

MsgBox "should be at record 3"
rst.Bookmark = szbookmark
rst.MoveNext

Me.Bookmark = rst.Bookmark

MsgBox "should be at record 2"
 
Jim?? Who's Jim? ;-)

If all you want is to move around the form's records in that
simple manner, then no you don't need to use the
recordsetclone object.

One important reason for using the recordsetclone is that
your form will be jumping from one record to another while
you're doing your thing. This kind of thing might be
annoying to your users.

For instance, if you don't want the form jumping between
records while you retrieve a value from the third record,
then you do not need to set/change the form's active record
at all. You could just move around in the recordsetclone
grabbing values. Also, you may want to use some of the
more sophisticated recordset methods such as FindFirst, etc,
then it is far better use the recordsetclone. In your case,
you never did say what you're trying to accomplish, so I
can't suggest a "better" way.
 
Marshall, a thousand apologies. Don't know where Jim came from. I see now where clone comes into play. My application is a one user database of old records where i'm searching for record company name and then if I find the first in the series, continue searching for #, eg RCA Victor 20437. The problem was that if there was no 20437 for RCA Victor, but there was one for Westminster 20437, my find would position the record there, instead of back up at the top of RCA Victor. So I was trying to use bookmark

I guess I got confused in that the articles plus the Access help doesn't make clear that you don't need to use clone approach if it's just a simple bookmark as above. It might help for help up front to distinguish between the two environments with examples for each

Thanks again for the insigh

Regards, Ron
 
cove3 said:
Marshall, a thousand apologies. Don't know where Jim came from. I see now where clone comes into play. My application is a one user database of old records where i'm searching for record company name and then if I find the first in the series, continue searching for #, eg RCA Victor 20437. The problem was that if there was no 20437 for RCA Victor, but there was one for Westminster 20437, my find would position the record there, instead of back up at the top of RCA Victor. So I was trying to use bookmark .

I guess I got confused in that the articles plus the Access help doesn't make clear that you don't need to use clone approach if it's just a simple bookmark as above. It might help for help up front to distinguish between the two environments with examples for each.


Glad I could help clarify something for you.

As far as Help needing help, we are all in agreement ever
since A2K Help replaced the excellent Help in A2 and A97.
While A2003 has made some improvements, it still needs a
**lot** of help and no matter how much we'd like to help
improve Help, it needs more help than any of us out here in
newsgroup land could ever provide, but we do try to keep
their feet to the fire ;-)

I wonder how that paragraph will show up on a relevancy
meter in a google search for "Help" ;-))
 
Marshall, just when you think you know everything, Access strikes you down. In going to apply my bookmark example to my actual form, I'm really running the code from a command button click which goes to a subform datasheet to do the search. In the following code for my main form "test2", I go to subform "test3". However, I'm getting an invalid bookmark property error when I try to save the bookmark. My main form has no data source

Private Sub findrec_Click(
Dim szbookmark As Strin
DoCmd.GoToControl "test3" ' go to subform test3 datashee
szbookmark = Me.Bookmark ' bookmark 1st record (invalid bookmark property setting here
DoCmd.GoToRecord , , acNext ' go to next record....this works if line above & below are delete
Me.Bookmark = szbookmark ' go back to 1st record
End Su

I'm awfully close on this

Regards, Ron
 
Marshall, there was a hint in paper 210060 about synchronizing forms that said not to use the Me form, but to use the full form reference

When i replaced Me!bookmark with forms!test2!test3.form.bookmark, everything seemed to work

Regards, Ron
 
cove3 said:
Marshall, there was a hint in paper 210060 about synchronizing forms that said not to use the Me form, but to use the full form reference

When i replaced Me!bookmark with forms!test2!test3.form.bookmark, everything seemed to work


Right, Me refers to the form that contains the code. Since
the mainform is unbound, there are no records to bookmark
(even if there were, they'd be the wrong ones). You could
still shorten the reference using Me but you still have to
go through the subform control:

Me!test3.Form.Bookmark
 
Back
Top