Results 1 to 5 of 5
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Stop error message when going past last record

    I have a listbox in a subform and on the main form, I have code that requerys the listbox when oncurrent.



    It works well, except, if I'm on the very last record and try to go to the next record, I get a 2455 error which debugs to the requery code. Obviously, there's not another record but from a user experience, it'd be ideal if there was no error and it did nothing. Any suggestions? I include my entire oncurrent code incase something else could be causing it.

    Code:
    Private Sub Form_Current()
    
        If Me.NewRecord Then
            DoCmd.GoToRecord , , acLast
        End If
    
    
        Dim rst As DAO.Recordset
        Dim lngCount As Long
    
    
        Set rst = Me.RecordsetClone
    
    
        If Not rst.EOF Then
          With rst
            .MoveFirst
            .MoveLast
            lngCount = .RecordCount
        End With
        End If
        
        Me.txtNavControls = Me.CurrentRecord & " of " & lngCount
        
        [Forms]![frmDetails]![subformAttachments].Form.
    [listbox1].Requery
    
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Just add an error handler and trap error 2445 and exit sub:
    http://allenbrowne.com/ser-23a.html

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Gicu View Post
    Just add an error handler and trap error 2445 and exit sub:
    http://allenbrowne.com/ser-23a.html

    Cheers,
    That worked! THanks!!

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Or something like this - the intrinsic navigation bar is disabled and custom buttons are programmed, and of course cannot be a datasheet form:
    Code:
    Public Sub ViewData(strDirection)
    'called by form used to view and navigate records
    
    
    If Not IsNull(Form_SampleInfo.tbxViewDataFormNAME) Then
        DoCmd.Close acForm, Form_SampleInfo.tbxViewDataFormNAME, acSaveNo
    End If
    
    
    With Form_SampleInfo
    
    
    .RecordsetClone.Bookmark = .Bookmark
    Select Case strDirection
        Case "Quit"
            DoCmd.Close acForm, "SampleInfo", acSaveNo
        Case "Next"
            .RecordsetClone.MoveNext
            If Not .RecordsetClone.EOF Then
                DoCmd.GoToRecord acForm, "SampleInfo", acNext
            Else
                .RecordsetClone.MoveLast
                MsgBox "Last record."
                .btnNext.Enabled = False
            End If
            .btnPrevious.Enabled = True
        Case "Previous"
            .RecordsetClone.MovePrevious
            If Not .RecordsetClone.BOF Then
                DoCmd.GoToRecord acForm, "SampleInfo", acPrevious
            Else
                .RecordsetClone.MoveFirst
                MsgBox "First record."
                .btnPrevious.Enabled = False
            End If
            .btnNext.Enabled = True
    End Select
    
    
    End With
    
    
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. stop word warning message when loading a mail merge
    By jalewis999 in forum Import/Export Data
    Replies: 8
    Last Post: 11-25-2020, 03:49 AM
  2. Replies: 1
    Last Post: 02-25-2017, 09:24 PM
  3. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  4. Error Message: No Current Record
    By arlrodri in forum Reports
    Replies: 2
    Last Post: 06-05-2014, 07:02 AM
  5. Duplicate Record Error Message!!
    By forumer in forum Forms
    Replies: 6
    Last Post: 03-14-2014, 07:25 AM

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