Jumat, 04 Maret 2016

Re: [MS_AccessPros] Requery datasheet

 

Troy-


If you've removed the record that has the focus (I assume because there's a filter to not show checked rows), where do you want the focus to go?  Next record?  Previous record?  Also, why are you requerying two objects?  Don't you just need to requery the current form?

You could try something like:

Private Sub Check13_AfterUpdate()
Dim rs As DAO.Recordset, lngID As Long

    ' Skip if there's an error
    On Error Resume Next

    ' Get a copy of the current recordset
    rs = Me.Recordset
    ' Go to the current row
    rs.Bookmark = Me.Bookmark
    ' Try to go to the next row
    rs.MoveNext
    ' Grab the Primary Key of the record
    lngID = Me.PKey  ' NOTE: Fix this to save the key using correct field name
    ' Requery to get rid of the checked row
    Me.Requery
    ' Attempt to reposition
    Me.Recordset.FindFirst "PKey = " & lngID
End Sub

The above code tries to find the "next" record and save its Primary Key.  You'll have to modify to use the real name (and data type) of the unique key for the recordset.  After a Requery, it then uses the key value to reposition the form.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)



On Mar 4, 2016, at 8:16 PM, Troy Sherven tsherven@mcd.net [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

I'm using Access 2010 and have a question about refreshing a datasheet form.  I've created a checkbox in the datasheet (for each record).  This checkbox is setup to remove a record from the datasheet.   I've created an event to requery the datasheet "after update" of the checkbox.  This removes the record from the datasheet.    Here's the event:

 

Private Sub Check13_AfterUpdate()

Me.Requery

Form_Completed.Requery

End Sub

 

The event works fine.  The problem I have is that if I'm working in the datasheet and am scrolled down to the bottom of the datasheet, if I click the checkbox it will requery the datasheet, and focus moves to the top of the datasheet again.  Is there any way to requery the datasheet but stay in the same position on the form?  It's annoying to have to scroll down again after every update. 

 

Any ideas?

 

Thanks,

 

Troy Sherven


__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

.

__,_._,___

Tidak ada komentar:

Posting Komentar