OrderBy when opening a form

Elly Woods

New member
Local time
Today, 10:57
Joined
Nov 29, 2013
Messages
5
Hi everyone,

I'm trying to have a form sorted in a particular order when it's opened.
When using the "order by" option in the properties sheet, it is sorted the way I want the first time I open the form. However, if I change the order afterwards while using the form (for instance, by right clicking and selecting another sort order), well the next time the form is opened, it is sorted with this new sort order, and not the default one.

So I tried to add the following code :
Code:
Private Sub Form_Open()
    Me.OrderBy "employee_name ASC"
    Me.OrderByOn = True
End Sub
Which failed epically. My error message is in French, so I'm not copying it here, but basically it says that I'm not using the right methods for the right events... Does someone have any insight on the matter?
 
Try
Code:
Private Sub Form_Open()
Me.OrderBy="employee_name ASC"
Me.OrderByOn = True
End Sub
 
Thanks for your fast reply, but no it didn't work, same error message.
 
The OrderBy property "sticks" only when the form was opened in design
view - then form view & a filter/sort applied - then saved.
To fix: open form in design view & clear out the Filter & OrderBy properties.
Save the form. This should remove any filter/sort when the form is
reopened in form view.
 
Yes that is true, but then I do not have my "default" sort order with which I want my form to open ...
 
Could u able to provide the sample of your mdb, remove confirdential matters before posting
 
Okay, I was absent-minded, my problem was in fact in the very first line of my code :
It should have been this :
Code:
Private Sub Form_Open(Cancel As Integer)

And you were right about the missing " = " sign :) Thanks a lot !
 

Users who are viewing this thread

Back
Top Bottom