Results 1 to 4 of 4
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    Need SQL for "Go to next record"

    I recognize that SQL doesn't have a 'Next record" but I have a "next record" button, how can I put in the SQL "Click that button?"



    Yes I realize this is HORRIBLE coding. I do not have the time or knowledge to do it properly. It's part of a "If the list box is blank, go to next record" for a massive data entry thing.

    So it's going to be something like

    IF [CountOfListbox] <1
    Then
    SQL code to click next button

    This will be in the 'on current' command. again, yes, this is terrible, terrible code. Please help.

    Edit: Here is my current code, doesn't work.

    Code:
    Private Sub Form_Current()
    Form.WorkplaceList.Requery
    If [CountOfListbox] < 1 Then DoCmd.RunMacro "MacroNextRecord"
    End Sub
    It "Kinda" works. On the records with an empty list box it gives me "You can't go to that record." The macro I created is just "Go to next record"

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    DoCmd.GoToRecord , , acNext

    Other similar code includes:
    DoCmd.GoToRecord , , acPrevious
    DoCmd.GoToRecord , , acFirst
    DoCmd.GoToRecord , , acLast

    Access help will give you details of other options like moving to a specific record
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by ridders52 View Post
    DoCmd.GoToRecord , , acNext

    Other similar code includes:
    DoCmd.GoToRecord , , acPrevious
    DoCmd.GoToRecord , , acFirst
    DoCmd.GoToRecord , , acLast

    Access help will give you details of other options like moving to a specific record
    It kinda works. It does properly skip over the records with a blank listbox, but now each time it gives the error "You can't go to the specified record."

    I wish so badly I had time to learn error handling. How can I turn off this error message?

    I've tried creating an "errorhandler" macro and set the "on error" property in Access to run that macro, with the macro set to run "ClearMacroError"

    Error still pops up. I'm so many hours into overtime now, this is due tomorrow morning.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    If you are at the last record, error 2105 occurs (can't go to the specified record)
    The error handling below deals with that

    Code:
    Private Sub cmdNext_Click()
    
    On Error GoTo Err_Handler
        
        DoCmd.GoToRecord , , acNext
        
    Exit_Handler:
        Exit Sub
        
    Err_Handler:
        If Err = 2105 Then
           'already at last record - exit without message
        Else
            MsgBox "Error " & Err.Number & " in cmdNext_Click procedure : " & Err.Description, vbOKOnly + vbCritical
        End If
        Resume Exit_Handler
        
    End Sub
    I normally have 4 buttons cmdFirst, cmdLast, cmdNext, cmdPrev
    I add code so that if I'm on the last record, cmdNext & cmdLast are disabled
    Similarly on first record cmdFirst & cmdPrev are disabled

    Effective error handling is VERY useful & its worth the time learning it many times over

    The attached file lists all Access error codes together with their description
    Most are very obscure but some like error 94 - invalid use of null - are common

    HTH
    Attached Files Attached Files
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Replies: 3
    Last Post: 07-28-2017, 12:12 PM
  2. Replies: 2
    Last Post: 12-23-2015, 09:32 PM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  5. Replies: 11
    Last Post: 03-29-2012, 02:32 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