Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013
    Posts
    8

    Unanswered: Next record Navigation from Combobox RS

    I have a time card entry form which contains a combo box for selection of an employee's id. Instead of having to go back to the combo box to select the next employee, I would like to have an alternate method - navigation buttons on the form. How do I do this?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Although I cannot see why you could not use the built-in navigation buttons (property NavigationButtons set to True) of the form, here's a solution:
    Code:
    Private Sub Combo0_AfterUpdate()
    
        Dim rst As DAO.Recordset
        
        Set rst = Me.RecordsetClone
        rst.FindFirst "SysCounter = " & Me.Combo0.Value
        If rst.NoMatch = False Then Me.Bookmark = rst.Bookmark
        rst.Close
        Set rst = Nothing
        
    End Sub
    
    Private Sub Command_Next_Click()
        
        Dim rst As DAO.Recordset
        
        Set rst = Me.RecordsetClone
        rst.FindFirst "SysCounter = " & Me.Combo0.Value
        If rst.NoMatch = False Then
            rst.MoveNext
            If rst.EOF = False Then
                Me.Bookmark = rst.Bookmark
                Me.Combo0.Value = Me.SysCounter
            Else
                MsgBox "This is the last record.", vbInformation, "No next record"
            End If
        End If
        rst.Close
        Set rst = Nothing
        
    End Sub
    
    Private Sub Command_Previous_Click()
        
        Dim rst As DAO.Recordset
        
        Set rst = Me.RecordsetClone
        rst.FindFirst "SysCounter = " & Me.Combo0.Value
        If rst.NoMatch = False Then
            rst.MovePrevious
            If rst.BOF = False Then
                Me.Bookmark = rst.Bookmark
                Me.Combo0.Value = Me.SysCounter
            Else
                MsgBox "This is the first record.", vbInformation, "No previous record"
            End If
        End If
        rst.Close
        Set rst = Nothing
    
    End Sub
    Note: SysCounter is the name of the column the values of which are displayed in the combo and it's a numeric data type. Form a text data type, use quotes in the criteria:
    Code:
        rst.FindFirst "SysCounter = '" & Me.Combo0.Value & "'"
    Have a nice day!

  3. #3
    Join Date
    May 2013
    Posts
    8
    Thanks. I came up with a similar solution over the weekend. I do appreciate your reply. BTW, the reason I couldn't use the built-in navigation was that the main form was unbound, and the records I was stepping through were those of a combo box recordset which was a filter to the subform dataset.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •