Requery Method (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 19:44
Joined
Sep 21, 2011
Messages
14,046
Me.CurrentRecord works for me?

Also shows the number of records affected if a filter is used.?
 

Tieval

Still Clueless
Local time
Today, 19:44
Joined
Jun 26, 2015
Messages
475
Code:
Private Sub tBlade_AfterUpdate()
Me.test.SetFocus
scanresults
DoCmd.GoToRecord , , acLast
If Me.CurrentRecord > 14 Then DoCmd.GoToRecord , , acPrevious, 14
End Sub
Error 2455 :banghead:
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:44
Joined
Sep 21, 2011
Messages
14,046
So inspect it in the debug window?

I do pretty much the same as you. I go to the end of the recordset of the query for the form, and then go back 5 records, as I have a emulated split form as a subform.

If I filter for a client and then inspect Me.CurrentRecord it shows the number of records as shown at the bottom of the form. If I remove the filter it does the same but for all the records returned by the query.

I do not know what error 2455 is and don't really want to have to go searching for what that error is.
 

isladogs

MVP / VIP
Local time
Today, 19:44
Joined
Jan 14, 2017
Messages
18,186
2455 = application defined or object defined error
91=object variable or with block variable not set.

My Access error codes example app is very useful for this...
or type e.g. Err.raise 2455 in the immediate window
 

Tieval

Still Clueless
Local time
Today, 19:44
Joined
Jun 26, 2015
Messages
475
If I add Debug.Print Me.CurrentRecord anywhere in the sub it returns nothing at all in the immediate window, I am guessing that this is the problem.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:44
Joined
Sep 21, 2011
Messages
14,046
What does Me.Name give you?

As this was an AfterUpdate event, I was assuming it is on a form?

Does scanresults change object focus? as you have Me at the start of the code?
 

Tieval

Still Clueless
Local time
Today, 19:44
Joined
Jun 26, 2015
Messages
475
Now things get interesting:
Code:
Private Sub tBlade_AfterUpdate()
Me.test.SetFocus
Debug.Print Me.Name
testresults
Debug.Print Me.Name
DoCmd.GoToRecord , , acLast
Debug.Print Me.Name
DoCmd.GoToRecord , , acPrevious, 14
Debug.Print Me.Name
End Sub
This gives the result as the main-form on all four occasions even the instance after setting the focus to the sub-form (test).
 

isladogs

MVP / VIP
Local time
Today, 19:44
Joined
Jan 14, 2017
Messages
18,186
Setting focus will have no effect on the Me. operator.
That refers to the currently active form you are working in.
 

Tieval

Still Clueless
Local time
Today, 19:44
Joined
Jun 26, 2015
Messages
475
So it would seem, this was all done on the assumption that the sub-form was the active form. I now have it working:
Code:
Me.test.SetFocus
testresults
DoCmd.GoToRecord , , acLast
If [test].Form.Recordset.RecordCount > 14 Then DoCmd.GoToRecord , , acPrevious, 14
Although this works, I think it shouldn't. Going to the last record should put it at the top of the form and you have to scroll up for earlier ones, to get it to the bottom of the form I moved it back 14.

Now I go to the last record and only move it back 14 if there are enough records and you would expect this to put the last record at the top if there were less than 15 records and you have to scroll up for the rest, it instead shows all the records (for example 4) as I want. :confused:
 

isladogs

MVP / VIP
Local time
Today, 19:44
Joined
Jan 14, 2017
Messages
18,186
Now I go to the last record and only move it back 14 if there are enough records and you would expect this to put the last record at the top if there were less than 15 records and you have to scroll up for the rest, it instead shows all the records (for example 4) as I want. :confused:

Say you have a form with sufficient space for 15 records.
If you have 16 records a scroll bar appears (obviously)
Selecting the last record using the navigation buttons both moves the focus and changes the records displayed

If you have 14 records, no scroll bar appears as it isn't needed.
Selecting the last record using the navigation buttons moves the focus but the records displayed do not change as there is no reason for them to do so
 

Tieval

Still Clueless
Local time
Today, 19:44
Joined
Jun 26, 2015
Messages
475
Hi Colin,
I do like to understand what I am doing rather than just sticking code in so hence my curiosity. A bit of confusion set in here as I think what I was seeing occurred when there was no If clause. It went to the last record as you state with no scroll bar but then attempted to move back, created the scroll bar, moved the record to the top and then failed due to lack of records.

Time to accept the quirk, many thanks for all your help.
 

isladogs

MVP / VIP
Local time
Today, 19:44
Joined
Jan 14, 2017
Messages
18,186
You're welcome but I'm not sure this is a quirk. Seems perfectly sensible to me.
 

Users who are viewing this thread

Top Bottom