Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Movelast not working as expected

    I have a sub-form based on a simple table query. The sub-form is "continuous".

    I have in the code sheet of the sub-form the following:

    Code:
    Private Sub Form_Open(Cancel As Integer)
        If Me.RecordsetClone.RecordCount > 0 Then
            Me.RecordsetClone.MoveLast
        End If
    End Sub
    What I want and what I expected is that the form will open displaying the last record at the bottom of the record's pane. It seems that the open code had no effect. The parent code does not contain any statements that would otherwise effect the recordsource of the sub-form.

    What do I need in addition to what I've already coded?

    Thanks,


    Bill

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Just curious -- is there any relationship between the subform and main form? Do you really only want to show 1 record from the table? If so, why would the subform be continuous?
    What is the sql for your recordset?

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think what you want is GoToRecord.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    There 100's of records. The record pane of the sub-form displays about 25 or so at a time. I just want the form to open positioned at the bottom. (As though the operator has scrolled to the last record).

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you try GoToRecord?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:
    Private Sub Form_Open(Cancel As Integer)
    DoCmd.GoToRecord , , acLast
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Paul, I tried this:

    Code:
    Option Compare Database
    Option Explicit
    Dim strTemp As Variant
    
    Private Sub Form_Open(Cancel As Integer)
        If Me.RecordsetClone.RecordCount > 0 Then
            Me.RecordsetClone.MoveLast
            strTemp = Me.RecordsetClone.SDate
            DoCmd.FindRecord strTemp, acStart
        End If
    End Sub
    Where SDate is unique to the recordset. The DoCmd.FindRecord blows up with a 2162:

    Click image for larger version. 

Name:	Abend-2162.jpg 
Views:	10 
Size:	22.1 KB 
ID:	13305

    I ran the code in Debug and verified that the value in strTemp was valid. In this case,
    it's "2013.07.28.0".

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Hi June,
    That's almost what I'm trying to accomplish. And while I do in fact display the last record in the recordset, it displays "alone" at the top of the sub-forms recordset, while what I'd like is for the last record to display at the bottom of the record pane with as many preceding records appearing above as will fit.
    Bill

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If all you want to do is move to the last record on the form or to a new record, try GoToRecord as shown in previous post.

    If you want to move to a specific record then why move to last?

    That is an odd structure for a date value. Why a string? SDate is not a date/time field?

    EDIT: I posted before seeing yours.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    In the current app, the SDate field means more than just the date. While it looks like just a date it isn't in that it includes a suffix that's part of the expression.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I tested in both Continuous and Datasheet view. Not getting the behavior you describe. The last record gets focus but I still see records above.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Maybe it's the difference between A2003 and A2010?

    The size of the sub-form frame is such that the form will show 22 records at a time. If I get the record count AND the count is greater than 22 is there a way with GoToRecord to go to record "count-21" ? I hate code like that, but I'm at a lost as to how to solve this.

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    This achieved the results. I just don't like hard-coded numbers.

    [CODEPrivate Sub Form_Open(Cancel As Integer)
    Dim intCount

    intCount = Me.RecordsetClone.RecordCount

    If intCount > 22 Then DoCmd.GoToRecord , , acGoTo, intCount - 21

    End Sub][/CODE]

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    June, as somewhat of an aside here, if the main form runs a sub in a general module that results in the addition of a record to the table upon which the recordsource query of the sub-form is based, will a Requery cause the sub-form's OnOpen code to run again? Intuitively I don't think so, but I want to run the GoToRecord again if the recordsource gets a record added to it. Am I clear here?

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The Open event will not run again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Null values being returned when use movelast
    By ssalem in forum Programming
    Replies: 6
    Last Post: 03-15-2013, 10:25 AM
  2. doubt with MoveLast
    By fabiobarreto10 in forum Forms
    Replies: 8
    Last Post: 04-11-2012, 12:41 PM
  3. Add operator not working as expected
    By g4b3TehDalek in forum Queries
    Replies: 4
    Last Post: 10-05-2011, 01:09 PM
  4. Relationships not working as expected
    By Poepol in forum Access
    Replies: 1
    Last Post: 04-29-2011, 05:39 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums