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 >>

How can I interact with other Office applications (Excel) using VBA in Access?
Need to write your Access data or query to an Excel file? Here is the how to do it: Most people are familiar with Excel and know how to use it well (enough), and when you start talking about Access, they get scared off, and don’t know what to do anymore. Well, here you are […]
How To Generate A XML File With Access VBA
XML is used to structure your data. You can send a CSV file to another person, but using XML, you can structure your data in a more elegant format, and get very specific about your fields, and what data is contained within your tags (your field names). This is different than a basic CSV file […]
Mouse Click Counter On Access Form
This post will demonstrate how you can count the number of clicks on your button in a certain time frame. It will function like a game . Here is the database form all in one: Option Compare Database Public m_dteStartTime As Date Public m_dteStopTime As Date Private Sub btnClicker_Click() Dim intValue As Integer Dim rst […]
Shared Access Database Management
Here is a handy setup for those who need to manage a shared access database. Either you can create this from scratch as per the example or add the new tables to your existing database. This setup will track: 1. the users currently using the database 2. what time the user and computer name currently […]
Support these sponsors:
