Declan Basile
asked on
Fixed Scroll When Requerying Form
How can I get the vertical scroll of the form to go back to where is was before I requeried a form? By default, focus is set to the first record after a requery. Also, when I save a reference to the current record and set the focus to the same record after requerying, the current record becomes the first record displayed on the form if that record isn't visible when the form is scrolled all the way up. Is there a way get a reference to the first *visible* record on the form and then set the focus back to that record after the requery?
Are you talking about a continuous form or a datasheet?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You will use the RecordsetClone:
Dim rs As DAO.Recordset
Dim lngID As Long
Set rs = Me.RecordsetClone
' Store the current ID of the form.
lngID = Me!ID.Value
' Run requery code.
' Look up the ID.
rs.FindFirst "ID = " & lngID
If Not rs.NoMatch Then
' Move form's current record to the record found.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
/gustav
Dim rs As DAO.Recordset
Dim lngID As Long
Set rs = Me.RecordsetClone
' Store the current ID of the form.
lngID = Me!ID.Value
' Run requery code.
' Look up the ID.
rs.FindFirst "ID = " & lngID
If Not rs.NoMatch Then
' Move form's current record to the record found.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
/gustav
@Gustav,
I know you know this, but you have to put the Set rs = me.recordsetclone line after the requery.
Dale
I know you know this, but you have to put the Set rs = me.recordsetclone line after the requery.
Dale
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's a continuous form. Also, I need to requery, not just refresh. I already tried finding the record after requerying. It keeps the same record as the current record but doesn't set the scroll to the same position as it originally was in most cases. I'm sorry I wasn't more clear about that in my original posting. It looks like the solution (attempting to read the position of the scroll thumb within the track) is complicated and inaccurate, and that the best thing for me to do is to live with the limitation of not being able to keep the scroll position when requerying a form. Thank you.