April 2006
Beginner
1114 pages
98h 16m
English
recordset.EOF[= setting]
True if the current record position is after the last record in the recordset. The following code uses the EOF property to test for the end of the recordset, adding names from the Employees table in the Northwind Traders sample database to the first column of the current worksheet:
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim strDbPath As String
Dim intIdx As Integer
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
strDbPath = "C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb"
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strDbPath
cnn.Open
rs.Open "Employees", cnn, adOpenStatic, adLockReadOnly, adCmdTable
rs.MoveFirst
intIdx = 1
Do Until rs.EOF
strName = rs!FirstName & " " & rs!LastName
ActiveSheet.Cells(intIdx, 1) = strName
rs.MoveNext
intIdx = intIdx + 1
Loop
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = NothingRead now
Unlock full access