Invalid Use of .Order By Property

David44Coder

Member
Local time
Tomorrow, 01:53
Joined
May 20, 2022
Messages
137
Could I have an example of the correct use for .OrderBy ? Currently giving error Invalid use of property
Oranges is the control source for textbox Text0. It is a Number field in the Forms RecordSource table


Code:
DoCmd.OpenForm "frmShow", acFormDS
 With Forms![frmShow]
.ShortcutMenu = False
 .OrderBy !Oranges ', Asc
 .Caption = "Testing"
End With
 
Did the OrderBy come up in intellisense?
That is normally for the data source, not the form?

Edit: after a quick test, as it does appear in intellisense
Code:
With Me
    .OrderBy = "Field2 DESC"
End With

works.?
MS info does not give an example, but does say 'a string expression' ?


However this forum does. :)
We have a good search function here, but noone ever seems to use it :(


And there is always Google?
 
Last edited:
hi @David44Coder,

you probably have to open form in Design view to change those things and save them

Rich (BB code):
Sub Form_ChangeDesign(pFrmName)
   Dim frm As form
   DoCmd.OpenForm pFrmName,acViewDesign
   Set frm = Forms(pFrmName)
   'do whatever...
   '
   DoCmd.Save acForm,pFrmName
   DoCmd.Close acForm,pFrmName
   Set frm = Nothing
End Sub

I normally put VBA on the form Load event to set OrderBy and OrderByOn when form is opened
 
Last edited:
hi @David44Coder,

you probably have to open form in Design view to change those things ...

Rich (BB code):
Sub Form_ChangeDesign(pFrmName)
   Dim frm As form
   DoCmd.OpenForm pFrmName,acViewDesign
   Set frm = Forms(pFrmName)
   'do whatever...
   '
   DoCmd.Save acForm,pFrmName
   DoCmd.Close acForm,pFrmName
   Set frm = Nothing
End Sub

I normally put VBA on the form Load event to set OrderBy and OrderByOn
I never even used OrderByOn in that above code, and it still worked?
 
I think you assign a string to .OrderBy :

.OrderBy= !Oranges & ""

I thought !Orange is a Field where the sort field is used:

.OrderBy="Orange"
 
Last edited:
I never even used OrderByOn in that above code, and it still worked?
yes, because form is already open -- however to set it to stick on a form that isn't, I think you'd need to do it in design ... I could be wrong about that though as I never used it that way
 
.OrderBy = "Oranges"
.OrderByOn =true
Ascending is default so not necessary to specify
 
Could I have an example of the correct use for .OrderBy ? Currently giving error Invalid use of property
Oranges is the control source for textbox Text0. It is a Number field in the Forms RecordSource table
Code:
With Forms![frmShow]
    .OrderBy = "Oranges"
End With
 
Apologies not answering sooner, but somehow the error vanished and had to give up trying to replicate it. But it still wasn't working until now.
Yes it wants a string and Crystal was right. I'd first left out the .OrderByOn =true, then had put it before the '.Order By =' which prevented it working.. many thanks.
 

Users who are viewing this thread

Back
Top Bottom