Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - Recordset Bookmark

Status
Not open for further replies.

sm43

Programmer
Dec 1, 2002
155
US

Hi,
This is concerning an Access 97 application.

I have a subform embedded in a form.

The subform has a record set. you can go to a particular row in the recordset by clicking - and

the cursor moves to that record. I have a button that does something and then refreshes the

overall form. When the form is refreshed, the cursor in the subform automatically jumps to the

first record in the recordset (i guess that's how Access is set up). I want to do this: after

form refresh, I want cursor to jump back to the record that it was on before the refresh.


I tried this:


Dim saveMark As String

saveMark = Forms!MainForm.NameOfSubFormControl.Form.Bookmark

Forms!MainForm.Refresh

Forms!MainForm.NameOfSubFormControl.Form.Bookmark = saveMark





I'm getting the following error on the very last line of code.

Invalid Bookmark


It actually was working fine for a while . now, I can't seem to get rid of this error.


Thanks.


Saad
 
I think the "something" you do before refreshing your form changes the recordset structure (or something like that) and all the bookmarks change too.
Maybe I'm wrong, but you can try to use Id instead of bookmark.

If you have an Id (unique value, or primarykey) on the recordset, save it into a variable before doing "something", and then, use the findfirst function on the recordset to retrieve the good line.
 
I had this problem some time ago. I discover that, like pop sodas and cigarrettes, I should stay ago from bookmarks. I solved the problem following the same algoritm that zrzr mentioned.

Bookmarks change everytime there is a refresh in the recordset. Therefore even if you safe the previous bookmark for the record, after a refresh that bookmark might still be assigned to the recordID or not. That's why it was working for some time and then "caput!!".

Ah ... the mysteries of ACCESS.
Vanleurth

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top