Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loosing cursor focus in datasheet view.

Status
Not open for further replies.

ccraw

Technical User
Jan 14, 2002
4
AU
Thanking any replies in advance.

Problem: I have a subform which is requeried on a user defined timer event (This is a must as the form has to show new, deleted and edited records ASAP). The form is usually requeried every 10 sec. When the datasheet is requeried the cursor location is sent directly to the first record.
Is there any way to automatically send the cursor back to the record that had the focus prior to the requery.

I have tried the bookmark property but as I dont know a great deal about it, I have not had much success.

 
I'm not sure the bookmarks will still be valid after a Requery. I don't think they will.

Before the requery, save the key fields of the current record. After the requery, use a FindFirst against a clone recordset to position to the same record, then copy the clone recordset's bookmark to the form's bookmark.
Code:
Private Procedure Form_Timer()
    Dim rst As Recordset
    Dim lngMyRecID As Long

    lngMyRecId = Me.[<key field>]
    Me.Requery
    Set rst = Me.RecordsetClone
    rst.FindFirst &quot;<key field> = &quot; & CStr(lngMyRecID)
    If Not rst.NoMatch Then
        Me.Bookmark = rst.Bookmark
    End If
    Set rst = Nothing
    (code to reset timer)
End Sub
Note: If the current record has been deleted, the FindFirst will fail and we'll leave the form positioned at the first record. You could change the FindFirst to use &quot;>=&quot; to instead find the next record in key sequence. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top