Dan Artuso said:
Dirk,
It works here. I just tested it out on 97.
Does that code not work for you?
Is it just a coincidence that it's been working for me?
At least in Access 2002 (and I wouldn't expect it to be different in
Access 97), if the act of requerying adds or deleted records from the
form's recordset, the bookmark you saved before requerying won't
necessarily take you to the same record.
I did this to test:
1. Create a form based on a test table with some records in it.
Autonumber primary key "ID". The form has records with ID values
through 72, then the next record has ID 170 (so there's a gap), and then
the next after that has ID 188.
2. Put a command button, cmdRequery, on that form. Here's the Click
event code:
Private Sub cmdRequery_Click()
Dim varBookmark As Variant
varBookmark = Me.Bookmark
Me.Requery
Me.Bookmark = varBookmark
End Sub
3. Positioned the form to the record with ID 170.
4. Inserted a record by code from the Immediate Window:
currentdb.Execute "INSERT INTO Table1 (ID, [Desc], Modified)
VALUES(150, 'Inserted record', Date())"
5. Back in the application window, clicked the cmdRequery button.
RESULT: the form is now positioned on record ID 150, the record I added
in code, not on the record I was on when I clicked the button.
Continuing the test, I did this:
6. Position the form again to record ID 170.
7. Deleted record ID 150 with code from the Immediate Window:
currentdb.Execute "DELETE FROM Table1 WHERE ID=150"
8. Clicked the cmdRequery button.
RESULT: the form is now positioned on record ID 188, the record *after*
the one I was on when I clicked the button.
So plainly the bookmark property is positional, and not based on a
physical record key or anything like that. Thus, you can't rely on a
saved bookmark to return you to the same record after a requery, unless
you are sure no records have been added or deleted -- in which case, why
requery at all?
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)