VBA/Excel/Access/Word/Access/Recordset Sort — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:46, 26 мая 2010
Sorting Records
Sub SortRecords()
Dim conn As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.Path & "\mydb.mdb"
Set myRecordset = New ADODB.Recordset
With myRecordset
.CursorLocation = adUseClient
.Open "Customers", conn, adOpenKeyset, adLockOptimistic
.Sort = "Country"
Do Until myRecordset.EOF
Debug.Print myRecordset.Fields("CompanyName").Value & ": " & myRecordset.Fields("Country").Value
.MoveNext
Loop
.Sort = ""
Do Until .EOF
Debug.Print myRecordset.Fields("CompanyName").Value & ": " & myRecordset.Fields("Country").Value
.MoveNext
Loop
.Close
End With
Set myRecordset = Nothing
conn.Close
Set conn = Nothing
End Sub