Results 1 to 4 of 4

Thread: dao recordset

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    Still trying to figure out how to sort descending with a dao recordset using the control, not sql.. can anyone help?

    Thanks,
    Thai

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Question Why not you use SQL Statement?

    Why don't you use SQL statement in your RecordSource statement?

    What type of control you're using? Data Control?
    Maybe you can do it like this:

    Over here i use the Biblio.mdb database as my sample code.
    I assume that you have add a DBGrid control and Data control in your form layout, and set the DBGrid DataSource to Data control.
    Code:
    Private Sub Form_Load()
    Data1.DatabaseName = App.Path & "\Biblio.mdb"
    'For Sorting the record base on the PubID Desc
    Data1.RecordSource = "SELECT * FROM Publishers Order By PubID DESC;"
    or
    'For Sorting the record base on the PubID Asc
    Data1.RecordSource = "SELECT * FROM Publishers Order By PubID ASC;"
    Data1.Refresh
    DBGrid1.Refresh
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168
    I don't want to use SQL because the recordset has already been opened and I want to sort then refresh and have the recordset be sorted descending. That is why I specified in my previous post that I didn't need an sql example. I already know how to do it that way, I just need an example of how to do it with dao's recordset sort/attribute properties.

    Thanks,
    Thai

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb Clone Recordset

    Hi Thai how about the Clone recordset? But this may not be the best solution.

    Code:
    Private Sub Form_Load()
    Dim OrgDb As DAO.Database
    Dim OrgRs As DAO.Recordset
    Dim CloneRs As DAO.Recordset
    Set OrgDb = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Biblio.mdb", False, False)
    Set OrgRs = OrgDb.OpenRecordset("SELECT * FROM Publishers ORDER BY PubID ASC;", dbOpenSnapshot)
    Set CloneRs = OrgRs.Clone
    CloneRs.MoveLast
    While Not CloneRs.BOF
        Debug.Print CloneRs.Fields(0)
        CloneRs.MovePrevious
    Wend
    CloneRs.Close
    Set CloneRs = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width