Change the base form sort property by macro

I want to set the display order of a form by a macro so that I can see it sorted in different ways depending on the condition. I tried setting the form property, but it didn’t change the order data rows were shown.

oForm.Order = """Clearance_Request_Date"" DESC"

This statement apparently doesn’t set the Order property of the form. What do I need to do?

The statement is correct. But it doesn’t take effect with existing data. You need to regenerate the view:

oForm.reload() following your statement will display the wanted sequence.

If this answers your question please click on the :heavy_check_mark: (upper left area of answer).

I apologize for not providing all my code. I am also adding a new filter and I reload the form after setting both properties. The filter works, but the Order doesn’t. I did a Msgbox of the oForm.Order after I set the value and it was Null.

What is your code? Even adding a filter I don’t have a problem.

is the form based on a Query or SQL that already has an ORDER BY clause?

No problem with query either. Got to be something else - got right field name?

Did all kinds of variations of this without problem:

Sub Main
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
oForm.Filter = "( ""DEFAULTTIMESTAMP"".""PHONE"" > '33' )"
'oForm.reload()
'oForm.Order = """PHONE"" ASC, ""NAME"" ASC"
oForm.Order = """PHONE"" ASC, ""NAME"" DESC"
oForm.reload()
MsgBox oForm.Order
End Sub

Full code and the variable name is correct:

OForm.Filter = (""RTI Status"" = 'Invited' )"
msgbox OForm.Order
OForm.Order = """Clearance_Request_Date"" DESC"
msgbox OForm.Order
 OForm.ApplyFilter=True
 OForm.Reload()

The first msgbox gives the default value of the order for the form, the second msgbox shows a null field.

Except for the missing quote mark at beginning of filter first line (typo I guess), used your exact code with my filter & order data & my form name and had no problem. Can’t see why you get NULL in second msgbox. There HAS to be something different in what you are using and what is displayed in your comment. Already know it is not a copy since there was a typo which causes an error. I see change from one message to the other.

Code I used:

Sub Main
OForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
OForm.Filter = "(""DEFAULTTIMESTAMP"".""PHONE"" > '33' )"
msgbox OForm.Order
OForm.Order = """NAME"" DESC"
msgbox OForm.Order
 OForm.ApplyFilter=True
 OForm.Reload()
End Sub

Executing this from button on form.