Requery and return to current record (1 Viewer)

cmray58

Registered User.
Local time
Yesterday, 21:18
Joined
Mar 24, 2014
Messages
70
I'm having trouble firing the requery command and returning to the current record instead of reverting back to record 1. I picked this up from someone else:

Code:
Dim Curr_Rec
Curr_Rec = Me.CurrentRecord
DoCmd.Echo False
Me.Requery
DoCmd.GoToRecord , , acGoTo, Curr_Rec
DoCmd.Echo True
Me.FirstName.SetFocus

I have this in the after update event of a field. However, it's reverting to the previous record, not the current record. I've attached the DB. Thanks in advance.
 

Attachments

  • MHAW.zip
    311.1 KB · Views: 63

cmray58

Registered User.
Local time
Yesterday, 21:18
Joined
Mar 24, 2014
Messages
70
Are you saying the way I'm using fundamentally won't work? Or is there something that needs to be adjusted? I'm trying to avoid redoing the entire thing for a new method.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:18
Joined
Aug 30, 2003
Messages
36,133
I don't use that method so I'm not sure, but that argument is an offset. I'm not on a computer so can't test.
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,439
It works for me, in the immediate window.?
However I am not adding a record.

I'd put a breakpoint in the code and walk through it
 

cmray58

Registered User.
Local time
Yesterday, 21:18
Joined
Mar 24, 2014
Messages
70
It works for me, in the immediate window.?
However I am not adding a record.

I'd put a breakpoint in the code and walk through it

It's only when you add a new record that I'm seeing the issue. You add the new record, enter the first field (Assessor), go to the last name, enter the last name, hit tab and it changes the record.
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,439
Try adding
Code:
If Me.dirty then Me.dirty = False
before setting curr_rec

or docmd acsaverecord option
 

cmray58

Registered User.
Local time
Yesterday, 21:18
Joined
Mar 24, 2014
Messages
70
Try adding
Code:
If Me.dirty then Me.dirty = False
before setting curr_rec

or docmd acsaverecord option

That didnt work either :(

It's really strange what's happening though. It's not even going to another record number. I.e., it still says record 19 of 19, but the data that displayed is different.
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,439
Use Paul's method then?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:18
Joined
Aug 30, 2003
Messages
36,133
No problem.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:18
Joined
May 21, 2018
Messages
8,602
Are you saying the way I'm using fundamentally won't work?
Yes, I am saying it is fundamentally wrong. The currentrecord returns the absolute position of a record. So assume you have the records
A
B
D
and you are on D. D is the third record. Now you add C. C Becomes the 3rd record. So your code sends you to C instead of returning to D.
 

Users who are viewing this thread

Top Bottom