Orderby problem with DESC

G

Guest

Hi all, (i posted this also in another form but no result...si i try again)
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
msgbox frm.OrderBy
End Function


I seems to work ok, the messagebox gives "[Global Title]" and the form sorts
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 (the messagebox shows nothing,
empty) and displays the original records from the record source without any
sort order.
So the DESC instruction is not accepted. The third time it is fine again,
the fourth time nothing ......ectectera

Can anyone help me on this ?
 
J

Jason Lepack

It works great for me. What code calls this function?

Cheers,
Jason Lepack
 
G

Guest

Simply what i wrote:
=SortForm([Form], "[Global Title]")
in the on-click property of a button....

but meanwhile i found that the underlying query is a join query of three
tables and the [Global Title] field was drawn from one of the joined tables.
Simply changing the join query's fieldname : [Global Title] as Globaltitle
......(without any spaces in the name) did solve my DESC problem......don't
ask me why


Thanks anyhow..
Rob
Jason Lepack said:
It works great for me. What code calls this function?

Cheers,
Jason Lepack

Hi all, (i posted this also in another form but no result...si i try again)
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
msgbox frm.OrderBy
End Function

I seems to work ok, the messagebox gives "[Global Title]" and the form sorts
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 (the messagebox shows nothing,
empty) and displays the original records from the record source without any
sort order.
So the DESC instruction is not accepted. The third time it is fine again,
the fourth time nothing ......ectectera

Can anyone help me on this ?
 

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