Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 788
  • Last Modified:

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?
0
Declan_Basile
Asked:
Declan_Basile
2 Solutions
 
Dale FyeCommented:
Are you talking about a continuous form or a datasheet?
0
 
Jack LeachProprietorCommented:
Try a Refresh instead of a Requery.  If it suits your needs data-wise, it'll keep the current record from being lost.

Otherwise, you may have to track the current record ID before the requery, then use a FindFirst for the recordset after the requery to get the cursor back to that location.  I tend to find this a bit sloppy though: screen flicker and not 100% every time.

As for determining the first visible record, that's quite difficult.  There's code around (check out www.lebans.com, I believe there's a demo there), which will attempt to read the position of the scroll thumb within the track, and thus get a "percentage" of how far in your records you are, then attempt to deduce the specific record (or thereabouts), but using it's AbsolutePosition within the recordset, again based on that percentage.

This was exceedingly difficult back in 2000 or so when UIs didn't vary so highly as they do these days, and I'm inclined to believe that Stephen did it more as a proof of concept rather than a real, working solution.  And Stephen Lebans was pretty much the best, so I'm not sure there's anything better.

Cheers,
-jack
0
 
Gustav BrockCIOCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dale FyeCommented:
@Gustav,

I know you know this, but you have to put the Set rs = me.recordsetclone line after the requery.

Dale
0
 
Gustav BrockCIOCommented:
Yes, you are right, thanks.

Dim rs As DAO.Recordset
 Dim lngID As Long

 ' Store the current ID of the form.
 lngID = Me!ID.Value

 ' Run requery code.

 Set rs = Me.RecordsetClone

 ' 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
0
 
Declan_BasileAuthor Commented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now