Jumat, 04 Maret 2016

RE: [MS_AccessPros] Requery datasheet


Hi John,


Think of my project as a task list with a couple hundred tasks.   I'm a standard form that includes 2 datasheet subforms.  On subform for tasks and the second subform for completed tasks.  When I check the completed checkbox, I want the record to move from the task list to the completed task list.  I'm using 2 different queries as the datasource for each datasheet.  The only difference between the two queries is the value of the checkbox (task list showing records where the checkbox value not like -1).  That's why I'm requerying two forms.  I want the record to disappear from the current form, show up on my completed form, and the focus to be on the next record instead of the top of the datasheet. 


Do  you think what you have below would accomplish what I'm trying to do?






From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Friday, March 04, 2016 1:31 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Requery datasheet





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


    ' 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


    ' 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()



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?




Troy Sherven



Posted by: Troy Sherven <tsherven@mcd.net>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)



Tidak ada komentar:

Posting Komentar