By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,651 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,651 IT Pros & Developers. It's quick & easy.

Sorting RecordsetClone?

P: n/a
Hi all,

I have a function I use to sort the recordset behind a form on designated
fields of the form (see code below). I pass the field name, and trigger this
function with the click of the field heading. However I'm using filters at
different times on the underlying form recordset, but want the functionality
of being able to sort the resulting recordset using my function.

I don't want to have to pass the filter to the fuinction if I can avoid it.
So im looking for a way to sort the recordsetclone.Ive tried the
recordset.sort property, but can't get it to work. Is there a way to do
this, is there a better approach.

Recordset --------->apply filter ------------->Sort result on various
fields.

-------------------------------------------------------
Function rstSort(sField As String)
Dim sortSql As String
Dim sOrder As String
Dim rs As Recordset
Set rs = Me.RecordsetClone
Dim sortString As String

If sortFlag Then
sortFlag = False
sOrder = ""
Else
sortFlag = True
sOrder = " DESC "
End If
rs.Sort = sField & sOrder

Set rs = Nothing
End Function
-------------------------------------------

Gerry Abbott

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gerry Abbott wrote:
Hi all,

I have a function I use to sort the recordset behind a form on designated
fields of the form (see code below). I pass the field name, and trigger this
function with the click of the field heading. However I'm using filters at
different times on the underlying form recordset, but want the functionality
of being able to sort the resulting recordset using my function.

I don't want to have to pass the filter to the fuinction if I can avoid it.
So im looking for a way to sort the recordsetclone.Ive tried the
recordset.sort property, but can't get it to work. Is there a way to do
this, is there a better approach.

Recordset --------->apply filter ------------->Sort result on various
fields.

-------------------------------------------------------
Function rstSort(sField As String)
Dim sortSql As String
Dim sOrder As String
Dim rs As Recordset
Set rs = Me.RecordsetClone
Dim sortString As String

If sortFlag Then
sortFlag = False
sOrder = ""
Else
sortFlag = True
sOrder = " DESC "
End If
rs.Sort = sField & sOrder

Set rs = Nothing
End Function
-------------------------------------------

Gerry Abbott


I would use OrderBy and OrderByOn. Ex:
Me.OrderBy = sField & sOrder
Me.OrderBYOn = True

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.