Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124

    How to I can create next record and previous record button in listbox


    Dear all,

    How to I can create next record and previous record button in listbox

    My attached file: http://www.mediafire.com/?i7aoewle7c3cep7

    Many thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A ListBox is a control on a Form. That Form has a RecordSource as does the ListBox. Which one do you want to go to the NextRecord?

  3. #3
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    Please see image below:



    In the form frmSearchExample have a listbox include all record

    I want to create a Next record button, when click it, in listbox, record will go to next record ...

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you want these buttons to do the same thing as the Up and Down arrow buttons on the keyboard?

  5. #5
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    Yes, I want these buttons to do the same thing as the Up and Down arrow buttons on the keyboard

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    See if this helps:

    From Access VBA Help:
    You can use the ListIndex property to determine which item is selected in a ListBox. Read/write Long.

  7. #7
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    Could you give me any code ???

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You will need some range checking but basically it will be something like:
    With Me.ListBoxName - using YOUR ListBoxName of course.
    .ListIndex = .ListIndex + 1
    End With
    Just make sure it will not go past the end.

  9. #9
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    I'm using the code below but not ok
    Code:
    Private Sub Form_Current()
    On Error GoTo Err_Form_Current
    
    'Provides record count for form
    
    Dim rs As DAO.Recordset
    Dim Count As Integer, Position As Integer
    
        Set rs = Me.RecordsetClone
        rs.MoveLast
        rs.MoveFirst
    
        Count = rs.RecordCount
        Me!txtRecCnt = "of  " & Count
    
        Position = Me.CurrentRecord
        Me!txtRecPos = Position
    
        
        If Position = 1 Then
            Me!gotoPrevious.Enabled = False
        Else
            Me!gotoPrevious.Enabled = True
        End If
    
        If Position > Count Then
            Me!gotoNext.Enabled = False
            Me!gotoNew.Enabled = False
            Me!txtRecCnt = "of  " & Position
        Else
            Me!gotoNext.Enabled = True
            Me!gotoNew.Enabled = True
            Me!txtRecCnt = "of  " & Count
        End If
       
        rs.Close
    
    Exit_Form_Current:
        Exit Sub
        
    Err_Form_Current:
        MsgBox Err.Description
        Resume Exit_Form_Current
        
    End Sub
    
    Private Sub gotoFirst_Click()
    On Error GoTo Err_gotoFirst_Click
    
    'Go to first record on form
    
        DoCmd.GoToRecord , , acFirst
    
    Exit_gotoFirst_Click:
        Exit Sub
    
    Err_gotoFirst_Click:
        MsgBox Err.Description
        Resume Exit_gotoFirst_Click
    End Sub
    
    Private Sub gotoLast_Click()
    On Error GoTo Err_gotoLast_Click
    
    'Go to last record on form
    
        DoCmd.GoToRecord , , acLast
    
    Exit_gotoLast_Click:
        Exit Sub
    
    Err_gotoLast_Click:
        MsgBox Err.Description
        Resume Exit_gotoLast_Click
    End Sub
    
    Private Sub gotoNew_Click()
    On Error GoTo Err_gotoNew_Click
    
    'Add New Record To Course List
    
        DoCmd.GoToRecord , , acNewRec
        [strSalespersonID].SetFocus
    
    Exit_gotoNew_Click:
        Exit Sub
    
    Err_gotoNew_Click:
        MsgBox Err.Description
        Resume Exit_gotoNew_Click
    End Sub
    
    Private Sub gotoNext_Click()
    On Error GoTo Err_gotoNext_Click
    
    'Go to next record in list
    
        DoCmd.GoToRecord , , acNext
    
    Exit_gotoNext_Click:
        Exit Sub
    
    Err_gotoNext_Click:
        MsgBox Err.Description
        Resume Exit_gotoNext_Click
    End Sub
    
    Private Sub gotoPrevious_Click()
    On Error GoTo Err_gotoPrevious_Click
    
    'Go to previous record
    
        DoCmd.GoToRecord , , acPrevious
    
    Exit_gotoPrevious_Click:
        Exit Sub
    
    Err_gotoPrevious_Click:
        MsgBox Err.Description
        Resume Exit_gotoPrevious_Click
    End Sub
    
    Private Sub New_Contact_Lable_Click()
        DoCmd.OpenForm "NewContact"
        DoCmd.Close acForm, "ContactDetail"
    End Sub

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    All of your code deals with the Recordset of the Form and not the ListBox. As I said you will need to manipulate the ListBox.ListIndex in order to affect the ListBox.

  11. #11
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    I can't to apply into my file (using the listbox). haizzzzzz

    http://www.mediafire.com/?mfuf56njozsazbs

  12. #12
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    Quote Originally Posted by RuralGuy View Post
    You will need some range checking but basically it will be something like:
    With Me.ListBoxName - using YOUR ListBoxName of course.
    .ListIndex = .ListIndex + 1
    End With
    Just make sure it will not go past the end.
    I'm using code below
    Code:
    Private Sub gotoNext_Click()
    Dim idx As Long
    
    With Me.lstItems
        idx = .ListIndex
        If .ListCount > 1 And idx < .ListCount Then
            .ListIndex = idx + 1
        End If
    End With
    End Sub
    Error below:

    run-time error '7777': You've used the ListIndex property incorrectly

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hmm...even though Help indicates that the ListIndex property is Read/Write, it looks like writing is not allowed. I'll have to do some more research.

  14. #14
    uronmapu is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    124
    Thanks you, please help me ....

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Maybe try setting the focus to the ListBox first.

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

Similar Threads

  1. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  2. Replies: 3
    Last Post: 11-23-2011, 12:25 AM
  3. Replies: 3
    Last Post: 11-18-2011, 03:53 PM
  4. Button to Create New Record
    By Pam Buckner in forum Access
    Replies: 3
    Last Post: 10-14-2011, 09:46 AM
  5. Replies: 1
    Last Post: 07-25-2011, 09:41 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