Orderby problem

G

Guest

Hi all,
I have a problem with sorting records from within visual basic.
I use the On Click property of a command button:
=SortForm([Form], "[Global Title]")
etc.

with this function in a standard module:

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
If Len(sOrderBy) > 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function


I seems to work ok, but it does not the second time i click on the button:
in fact the second time, it should reverse the sort order. Instead it removes
the content of the field.orderby property and displays the original records
from the record source without any sort order.
So the DESC instruction is not accepted.

Can anyone help me on this ?
 
S

Scott McDaniel

Hi all,
I have a problem with sorting records from within visual basic.
I use the On Click property of a command button:
=SortForm([Form], "[Global Title]")
etc.

Perhaps it'd be easier to check the last 5 characters in the OrderBy and see if they contain the phrase " DESC":

with this function in a standard module:

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
If Len(sOrderBy) > 0 Then

If Len(frm.OrderBy)>0 Then
If Right(frm.OrderBy,5)<> " DESC" Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function


I seems to work ok, but it does not the second time i click on the button:
in fact the second time, it should reverse the sort order. Instead it removes
the content of the field.orderby property and displays the original records
from the record source without any sort order.
So the DESC instruction is not accepted.

Can anyone help me on this ?

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
G

Guest

Hi Scott, Thanks for replying...

I tried:

msgbox frm.orderby

as last line in the SortForm function.
The first time it gives me "[Global Title]", the seond time it gives nothing
(empty), the third time "[Global Title]" again etcetera


Any clou ?

Rob

Scott McDaniel said:
Hi all,
I have a problem with sorting records from within visual basic.
I use the On Click property of a command button:
=SortForm([Form], "[Global Title]")
etc.

Perhaps it'd be easier to check the last 5 characters in the OrderBy and see if they contain the phrase " DESC":

with this function in a standard module:

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
If Len(sOrderBy) > 0 Then

If Len(frm.OrderBy)>0 Then
If Right(frm.OrderBy,5)<> " DESC" Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function


I seems to work ok, but it does not the second time i click on the button:
in fact the second time, it should reverse the sort order. Instead it removes
the content of the field.orderby property and displays the original records
from the record source without any sort order.
So the DESC instruction is not accepted.

Can anyone help me on this ?

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
S

Scott McDaniel

Hi Scott, Thanks for replying...

I tried:

msgbox frm.orderby

as last line in the SortForm function.
The first time it gives me "[Global Title]", the seond time it gives nothing
(empty), the third time "[Global Title]" again etcetera

There was a missing End If in the code ... did you catch that?

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
If Len(sOrderBy) > 0 Then
If Len(frm.OrderBy)>0 Then
If Right(frm.OrderBy,5)<> " DESC" Then
sOrderBy = sOrderBy & " DESC"
End If
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
msgbox frm.OrderBy
End Function




Any clou ?

Rob

Scott McDaniel said:
Hi all,
I have a problem with sorting records from within visual basic.
I use the On Click property of a command button:
=SortForm([Form], "[Global Title]")
etc.

Perhaps it'd be easier to check the last 5 characters in the OrderBy and see if they contain the phrase " DESC":

with this function in a standard module:

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
If Len(sOrderBy) > 0 Then

If Len(frm.OrderBy)>0 Then
If Right(frm.OrderBy,5)<> " DESC" Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function


I seems to work ok, but it does not the second time i click on the button:
in fact the second time, it should reverse the sort order. Instead it removes
the content of the field.orderby property and displays the original records
from the record source without any sort order.
So the DESC instruction is not accepted.

Can anyone help me on this ?

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top