Record Selector command button

cdegroot

New Member
Joined
Nov 25, 2002
Messages
9
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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,221,814
Messages
6,162,135
Members
451,744
Latest member
outis_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top