Sorting a Recordset 
Author Message
 Sorting a Recordset

On the 10 April there is a message regarding sorting a
recordset however I have been unable to find the
solution.  Can you please repost it.  I have written the
following VBA code in Excel however I would like the list
in the Combo box (cmbclientname) to be sorted.

    Dim db As Object
    Dim rs As Recordset
    Dim x As Integer

    'Populate the client list box
    Set db = OpenDatabase(Name:=Clients)
    Set rs = db.OpenRecordset(Name:="ClientID")
    For x = 0 To rs.RecordCount - 1
        cmbClientName.AddItem (rs!ClientName)
        rs.MoveNext
    Next x
    rs.Close
    db.Close



Fri, 11 Mar 2005 10:45:12 GMT  
 Sorting a Recordset
Create a query that is sorted in the order you want and open
the recordset on that. But, why would you not just use the
query as the RowSource of the ListBox? There's no need to
create a ValueList.

--
Larry Linson      http://www.ntpcug.org -- North Texas PC
User Group
  http://members.tripod.com/ntaccess -- NTPCUG Access Spl.
Interest Group
  http://members.tripod.com/accdevel -- Access Samples and
Examples
  http://members.tripod.com/appdevissues -- Presentations
for Download


Quote:
> On the 10 April there is a message regarding sorting a
> recordset however I have been unable to find the
> solution.  Can you please repost it.  I have written the
> following VBA code in Excel however I would like the list
> in the Combo box (cmbclientname) to be sorted.

>     Dim db As Object
>     Dim rs As Recordset
>     Dim x As Integer

>     'Populate the client list box
>     Set db = OpenDatabase(Name:=Clients)
>     Set rs = db.OpenRecordset(Name:="ClientID")
>     For x = 0 To rs.RecordCount - 1
>         cmbClientName.AddItem (rs!ClientName)
>         rs.MoveNext
>     Next x
>     rs.Close
>     db.Close



Fri, 11 Mar 2005 11:24:49 GMT  
 Sorting a Recordset
The answer was probably something like, "open your recordset on a SQL
SELECT statement that orders the records the way you want".  Like
this, maybe:

    Dim strSQL As String

    strSQL = "SELECT ClientName FROM Clients " & _
                    "ORDER BY ClientName"

    Set rs = db.OpenRecordset(strSQL)

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> On the 10 April there is a message regarding sorting a
> recordset however I have been unable to find the
> solution.  Can you please repost it.  I have written the
> following VBA code in Excel however I would like the list
> in the Combo box (cmbclientname) to be sorted.

>     Dim db As Object
>     Dim rs As Recordset
>     Dim x As Integer

>     'Populate the client list box
>     Set db = OpenDatabase(Name:=Clients)
>     Set rs = db.OpenRecordset(Name:="ClientID")
>     For x = 0 To rs.RecordCount - 1
>         cmbClientName.AddItem (rs!ClientName)
>         rs.MoveNext
>     Next x
>     rs.Close
>     db.Close



Fri, 11 Mar 2005 11:27:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Sorting a recordset based on another recordset

2. Sorting a Recordset using Visual Basic

3. Sorting Child Recordsets...

4. sorting the recordset

5. SQL - sorting one recordset by another's values

6. Sorting ADO Recordset

7. Weird recordmovement after sorting a recordset.

8. How can I sort my Recordset?

9. Sorting a Recordset

10. Sorting ADO Recordset

11. VB6 Function to Sort ADO Recordset

12. Re-sorting a RecordSet

 

 
Powered by phpBB® Forum Software