Repositioning A Cursor

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:07
Joined
Sep 12, 2006
Messages
16,048
Here's another one.

I have a continuous subform, and lets say I am on the 4th record.


From the main form, I want to requery this form, and return to the same eg the 4th row.

ACTUALLY WHAT I REALLY want to do is refresh the data in a single calculated field on the 4th row (refresh isn't doing it. requery is, but places the cursor on the first row) - but I am struggling to find a syntax that does this for me.

Any suggestions.
 
A control that has a 'control source' has a Requery method. Just Requery the individual control.
Code:
Me.sfm.Form.MyControl.Requery
Cheers,
 
I use this to go back to the same record:

http://www.baldyweb.com/Requery.htm

Does requerying the control instead of the form work for you?
 
You can also do this if your operation might have deleted the current record ...
Code:
   Dim tmp As Single
   tmp = Me.Recordset.AbsolutePosition
   Me.Requery
   Me.Recordset.AbsolutePosition = tmp
 
lagbolt

thanks - I had tried the first method you suggested, but for some reason, it didn't work - although it didn't error.

the second method worked with a minor change (to refer to the subform) , as follows. Don't think I used absoluteposition before, so that was the key

Code:
    Dim tmp As Long
    tmp = Parent!SubformName.Form.Recordset.AbsolutePosition
    Parent!SubDOCs.Requery
    Parent!SubFormName.Form.Recordset.AbsolutePosition = tmp
 
I use this to go back to the same record:

http://www.baldyweb.com/Requery.htm

Does requerying the control instead of the form work for you?

paul

thaks for that idea - i used lagbolt's idea, as the recordset i was using definitely did not change as a result of the requery. i just needed to get back to the same record - but i can see uses for your suggestion in a different circumstance.
 
No problem Dave; lagbolt's is simpler if the records don't change, so I don't blame you. I would be a little wary of the Single data type (floating point issues), but perhaps it doesn't cause problems in this instance.
 
I would be wary using AbsolutePosition. In my experience it doesn't always give desired results and I think in the help files there's a caution about using this property as the cursor position.

I would use the CurrentRecord property with the Move method of the recordset:
Code:
    Dim pos As Long
    
    pos = Parent!SubformName.CurrentRecord
    Parent!SubformName.Requery
    Parent!SubformName.Form.Recordset.Move pos
 
My mistake. I meant PercentPosition, which is why I used the single.
Code:
   Dim tmp As Single
   tmp = Me.Recordset.PercentPosition
   Me.Requery
   Me.Recordset.PercentPosition = tmp
Cool thread though. Lot of ways to skin this cat.
Cheers,
 
Well, I did use absoluteposition - but I changed the single to a long.

I doubt if percent position would be 100% reliable though.

vbainet's currentrecord sounds good, too.


thanks for all the thoughts.
 
And I was unaware of PercentPosition. Learn something new every day!
 
Even the PercentPosition is also an approximation but it does present some interesting ideas for all.

Here's what the help files mentions about this:

Sets or returns a value indicating the approximate location of the current record (current record: The record in a recordset that you can modify or retrieve data from. There is only one current record in a recordset, but a recordset may have no current record, for example, after a record has been deleted from a dynaset-type recordset.) in the Recordset object based on a percentage of the records in the Recordset.

It goes on to warn:

Using the PercentPosition property to move the current record to a specific record in a Recordset object isn't recommended?the Bookmark property is better suited for this task.
 
Why requery or move at all? Just try using

Me.Recalc
 

Users who are viewing this thread

Back
Top Bottom