Sabtu, 05 Maret 2016

Re: [MS_AccessPros] Requery datasheet

 

Troy-


Ah, this is a Datasheet or Continuous form, right?  My code will move the selected record, but the screen doesn't scroll.  If you look at the record selector, it should not be highlighted for the first row.  You need one more statement just after the FindFirst to (I hope) do what you want:

    Me.SelTop = Me.Recordset.AbsolutePosition

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 11:56 PM, Troy Sherven tsherven@mcd.net [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

I have tried both solutions and get the same result.  The focus goes back to the top of the datasheet after I click Check13.

 

Here's John's solution:

 

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

    Set 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.IDNUMBER  ' 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 "idnumber = " & lngID

 

End sub

 

Here's Darrell's solution:

 

  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

    Set rs = Me.Recordset

    ' Go to the current row

    rs.Bookmark = Me.Bookmark

    ' Try to go to the next row

    rs.MoveNext

    ' Check for EOF

     If rs.EOF Then

             ' Move to the previous record

            rs.Move -1, rs.Bookmark

     End If

    ' Grab the Primary Key of the record

    lngID = Me.IDNUMBER  ' 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 "idnumber = " & lngID

End Sub

 

 

Any ideas?

 

Thanks for your help!

 

Troy

 

 

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

 

 

Bad "air code" on my part.  I think someone else has already pointed out that it should be:

 

SET rs = Me.Recordset

 

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 9:02 PM, Troy Sherven tsherven@mcd.net [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

John,

 

Thanks for the help.  I'm trying to use what you sent me, but am getting a "compile error – invalid use of property" on the line rs=Me.Recordset (the rs is highlighted).  I did change the name of the primary key field (the field name is idnumber). 

 

Any ideas?

 

 

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.idnumber  ' 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 "idnumber = " & lngID

End Sub

 

Thanks!

 

Troy

 

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

 

 

Troy-

 

Ah, now I understand why you're doing the second Requery.  Yes, my code should work as long as you add the second Requery and modify the code to search on the actual Primary Key field name.

 

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:50 PM, Troy Sherven tsherven@mcd.net [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

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?

 

Thanks,

 

Troy

 

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

 

 

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

.

__,_._,___

Tidak ada komentar:

Posting Komentar