Recordset In VBA – PT3

In this video we are talking about how to use MS Access form and bind in to a recordset In VBA. We talk about how to navigate the recordset.

Here is an image of the way the process of the recordset’s methods work:

Here’s the video:


Option Compare Database

Dim m_rst As Recordset


Private Sub btnMoveFirst_Click()
    m_rst.MoveFirst
    
    Me.txtCustomerID = m_rst.Fields("CustomerID")
    Me.txtCustomerName = m_rst.Fields("CompanyName")
            
End Sub

Private Sub btnMoveLast_Click()
    m_rst.MoveLast
    
    Me.txtCustomerID = m_rst.Fields("CustomerID")
    Me.txtCustomerName = m_rst.Fields("CompanyName")
                
End Sub

Private Sub btnNext_Click()
        
    Debug.Print "Move Next: " & m_rst.AbsolutePosition
    
    If Not m_rst.EOF Then
        m_rst.MoveNext
        
        'check the eof again....
        If Not m_rst.EOF Then
            Me.txtCustomerID = m_rst.Fields("CustomerID")
            Me.txtCustomerName = m_rst.Fields("CompanyName")
        End If
    Else
        MsgBox "You have reached the end of the file."
        
        Exit Sub
    End If

End Sub

Private Sub btnPrevious_Click()
    'Dim rst As Recordset
    
    Debug.Print "Move Previous: " & m_rst.AbsolutePosition
    

    If Not m_rst.BOF Then
        m_rst.MovePrevious
        
        'check the eof again....
        If Not m_rst.BOF Then
            Me.txtCustomerID = m_rst.Fields("CustomerID")
            Me.txtCustomerName = m_rst.Fields("CompanyName")
        End If
    Else
        MsgBox "You have reached the beginning of the file."
        Exit Sub
    End If

End Sub

Private Sub Form_Load()
    'Customize this when you want to have more control over the form's workings.
        
    'Set the recordsource to the "Customer" table
    Me.RecordSource = "Customers"
    Set m_rst = Me.RecordsetClone
    
End Sub


<< Recordset In VBA – PT2 | Recordset In VBA – PT4 >>

Offsite Related Information:

“Go Fund Me” Page


($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: ,