I toggled off the record selector on a form so that I could control actions with command button. Upon form load, it goes to new record. I have a command button that upon click will perform an update routine to a record set using ADO.
I want to add a command button to find and display first record and also another to find and display last record. It is not difficult to perform the select of a record set and either MOVEFIRST or MOVELAST. I haven't figured out how to display selected record in the basic form that is used to update the table.
Here is the subroutine to open a record set and find the first record:
Sub MoveFirst()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim frm As Form
Dim strConn As String
' Set conn = New ADODB.Connection
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Select * from tblsodt_Control ORDER BY ID", _
conn, adOpenForwardOnly, adLockReadOnly
rst.MoveFirst
' Do While Not rst.EOF
' Debug.Print "New Record --------------"
For Each fld In rst.Fields
Debug.Print fld.Name & " = " & fld.Value
Next
' rst.MoveNext
' Loop
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
MsgBox "Results are in the Immediate window."
End Sub
Obviously, it will display to the immediate window. I also want to display in the fields of the form that initiates this subroutine.
Thanks,
Craig
I want to add a command button to find and display first record and also another to find and display last record. It is not difficult to perform the select of a record set and either MOVEFIRST or MOVELAST. I haven't figured out how to display selected record in the basic form that is used to update the table.
Here is the subroutine to open a record set and find the first record:
Sub MoveFirst()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim frm As Form
Dim strConn As String
' Set conn = New ADODB.Connection
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Select * from tblsodt_Control ORDER BY ID", _
conn, adOpenForwardOnly, adLockReadOnly
rst.MoveFirst
' Do While Not rst.EOF
' Debug.Print "New Record --------------"
For Each fld In rst.Fields
Debug.Print fld.Name & " = " & fld.Value
Next
' rst.MoveNext
' Loop
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
MsgBox "Results are in the Immediate window."
End Sub
Obviously, it will display to the immediate window. I also want to display in the fields of the form that initiates this subroutine.
Thanks,
Craig