Adjusting code for preventing "Jumping view" after requery (1 Viewer)

WojtekKowalski

New member
Local time
Today, 13:22
Hi:)

I have code to prevent "jumping view" after requiring form, so that whenever I requery data, cursor, view and scrollbar stay in the same place. It works perfectly fine.
Form:
Continuous form with header.
Code:
Code:
    Dim lngSelTopCurrentRecord As Long
    Dim lngRowsFromTop As Long
    Dim lngSelTopUppermostRecord As Long
    
    Me.RobotName.SetFocus
    lngSelTopCurrentRecord = Me.Form.SelTop
    Me.Form.Painting = 0

    lngRowsFromTop = (Me.Form.CurrentSectionTop - 450) \ 510
    
    Me.Form.Recordset.Move -1 * (lngRowsFromTop - 1)

    lngSelTopUppermostRecord = Me.Form.SelTop

    Me.Form.Requery
    Me.Form.Recordset.MoveLast

    Me.Form.SelTop = lngSelTopUppermostRecord
    Me.Form.SelTop = lngSelTopCurrentRecord
    Me.Form.Painting = -1

I had to change my application, so now it is Single Form with header and within this form I have Subform - Datasheet Form.
I have placed above mentioned code in the subform. The problem is I need to adjust somehow these numbers "450" and "510" otherwise view and scrollbar will be jumping after requery , but to be honest I don't know what actually these numbers are for. I'm guessing they somehow describe Height of workspace. Can someone help me adjust them to my current structure?
 

bastanu

AWF VIP
Local time
Today, 04:22
Usually when requerying you want to record the unique ID of the record you are in, turn off the screen update, requery and go back to the record:
Code:
DIm lId as Long,rs as DAO.Recordset
lID=Me.txtYourUniqueID
Application.Echo False
Me.Requery
Set rs=Me.recordsetclone
rs.FindFirst "[YourID]=" & lID
Me.Bookmark=rs.bookmark
Set rs=Nothing
Application.Echo True
Cheers
 

WojtekKowalski

New member
Local time
Today, 13:22
Usually when requerying you want to record the unique ID of the record you are in, turn off the screen update, requery and go back to the record:
Code:
DIm lId as Long,rs as DAO.Recordset
lID=Me.txtYourUniqueID
Application.Echo False
Me.Requery
Set rs=Me.recordsetclone
rs.FindFirst "[YourID]=" & lID
Me.Bookmark=rs.bookmark
Set rs=Nothing
Application.Echo True
Cheers
Thank you for your insight. Unfortunately using this code, view is jumping after requery. What I understand by jumping - Let's say before requery record in the middle of the screen is selected, after requering the same record is selected, but unfortunately it's not anymore in the middle of the screen as it was beforehand, because scrollbar moved so that e.g. record now is somewhere at the end of the screen, which makes it annoying for the user.
 

Users who are viewing this thread

Top Bottom