Stay on Same Cell after Requery

  • Thread starter Thread starter TK
  • Start date Start date
T

TK

I have a form in datasheet view that I requery to reflect
changes after edits. This works fine with a requery in the
the AfterUpdate event, but this changes the selected cell
to the first column in the first row of the datasheet. How
can I re-select the cell that was selected prior to the
requery?
 
NOT the only way to do this is to remeber Currentrecord
value.

Dim lCurPos as Long

'inside requery procedure
lCurPos = Me.CurrentRecord


After requery:
Do While Me.CurrentRecord < lCurPos
DoCmd.GoToRecord acDataForm, Me.Name, acNext
Loop

Better way to do this is to remember bookamrk value for
recordsetclone for this form. After requery You can set
bookmark direct in code. See the help files for more
informations.
 
Thanks for the response,

That will work to move to the correct record, but the
first column will be selected. I want to make the same
cell selected after the requery.

The best I can figure out is to save the Me.SelTop and
Me.SelLeft properties prior to the requery in the
AfterUpdate event code and to use these values to re-
select the same cell afterwards. The following code works:

Private Sub Form_AfterUpdate()
Dim SelectTop, SelectLeft
SelectTop = Me.SelTop
SelectLeft = Me.SelLeft
Me.Refresh
Me.SelTop = SelectTop
Me.SelLeft = SelectLeft - 1
End Sub

This accomplishes what I wanted in my initial post, (note
that the SelLeft property has to be adjusted by 1 due to a
bug in Access 2000 and up), but it isn't perfect since the
User probably wanted to move to another record, not just
stay at the same spot. To do this right I need to identify
the cell that the user selected that fired off the initial
Update event. I'm not sure which property would provide
this.

Any suggestions?
 
Back
Top