Keep Cursor in same spot after Requery (1 Viewer)

omarrr128

Member
Local time
Today, 23:34
Joined
Feb 5, 2023
Messages
69
Currently in My database there is an area for Staff to add some notes. Problem is that when the form does a Requery the cursor will move to a field in the top Record and also selects all the data in that record.

Is it possible to keep the Cursor in the exact same spot after query so Staff can carry on typing like nothing happened and without being interrupted?

Im not very good with code so if someone could write out code for me I would be very grateful :).

File attached if it helps.

 

Attachments

  • SMH Porter 2023 Combined.accdb
    5.4 MB · Views: 68

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:34
Joined
May 7, 2009
Messages
19,245
instead of Me.Requery, you can use Me.Recordset.Requery
 

omarrr128

Member
Local time
Today, 23:34
Joined
Feb 5, 2023
Messages
69
instead of Me.Requery, you can use Me.Recordset.Requery
i tried that. It keeps it on the same record instead of going to the top one but it will still select all the data in the field. i need some code for it to go to the end of the field. I tried to do the sel start and length but couldnt get far
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:34
Joined
Feb 19, 2013
Messages
16,618
Check out the recordset absoluteposition property. On my phone so can’t really do any more than something like

dim p as long
Dim s as long
S=myfield.selstart
P=me.recordset.absoluteposition
Me.requery
me.recordset.absoluteposition=p
Myfield.selstart=s

Will need more work jf the form is scrollable and the form has been scrolled
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:34
Joined
May 7, 2009
Messages
19,245
try this.
 

Attachments

  • SMH Porter 2023 Combined (1).accdb
    5.4 MB · Views: 77

omarrr128

Member
Local time
Today, 23:34
Joined
Feb 5, 2023
Messages
69
try this.
It half worked. In most cases it works but if a new job is booked and all the records shift down by 1 row then it will edit the row that has moved down in to its place. I have found a fix though and just made it that setfocus after requery goes to a locked textbox.

Thank you :)

I was looking more in to the previous request i had with locking the start time and found this link. Do you think could install it? Ive tried switching the names out but it doesnt seem to work at all.

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:34
Joined
Feb 19, 2002
Messages
43,302
Requery is NOT the method intended for saving the current record. Requery tells Access to rerun the form's RecordSource query and since that reloads the form's RecordSource, focus moves back to the first row. Saving the current row is a side effect of Requery and therefore, you are experiencing unintended consequences by using the wrong command.

Use
DoCmd.RunCommand acCmdSaveRecord


or

Me.Dirty = False --- but always document this since it is not obvious what it does.
 

XPS35

Active member
Local time
Tomorrow, 00:34
Joined
Jul 19, 2022
Messages
159
Problem is that when the form does a Requery the cursor will move to a field in the top Record and also selects all the data in that record.
What is the use of the requery?
 

omarrr128

Member
Local time
Today, 23:34
Joined
Feb 5, 2023
Messages
69
What is the use of the requery?
just to refresh the page automatically so new jobs appear. I have found a decent fix for it which is just to set focus to a text box that cant be edited so no text will be entered anywhere after requery if that makes sense
 

omarrr128

Member
Local time
Today, 23:34
Joined
Feb 5, 2023
Messages
69
updated
 

Attachments

  • 2023 Porter New System Frontend.accdb
    5.1 MB · Views: 63

Users who are viewing this thread

Top Bottom