Article ID: 103808
Article Last Modified on 1/8/2003
Data1.RecordSource = "Select * From Publishers Order By PubID"
The ORDER BY clause technique is also more flexible than the Index
property technique. Using the ORDER BY clause, you can sort on any
field, and no specified index is required.
Data1.Recordset.Sort = "City DESC" '** No error occurs
Data1.Refresh '** No change in order occurs
If you try to sort the Publishers table by City, nothing happens. But if
you use an ORDER BY clause in an SQL statement, as in the following
example, you will see the database data displayed in descending order
by the City names:
Data1.RecordSource = "Select * From Publishers Order By City DESC"
Data1.Refresh
Sub Command1_Click ()
Dim db As Database
Dim Qd As QueryDef
Dim Sn As Snapshot
Data1.DatabaseName = "c:\vb\biblio.mdb"
Data1.RecordSource = "Authors"
Data1.Refresh
' Open the "By date" query
Set Qd = Data1.Database.OpenQueryDef("By date")
' Set the value of the dp parameter
Qd!dp = 1991
' create a snapshot off of querydef
Set Sn = Qd.CreateSnapshot()
Sn.MoveFirst
Do Until Sn.EOF
For i = 1 To Sn.Fields.Count - 1
Print Sn(i) & " "; 'Display results of query
Next
Print
Sn.MoveNext
Loop
Sn.Close
Qd.Close
db.Close
End Sub
Additional query words: 3.00 docerr
Keywords: KB103808