sort table via vba code on form load

murray83

Games Collector
Local time
Today, 02:13
Joined
Mar 31, 2017
Messages
827
have read else where that the following code in form load would help sort by what you want

Code:
Me.OrderBy = ""

my one question i want to sort my table by the status when its "Waiting" ( not my idea manager request )

so would the code now look like this as have tried and no dice

Code:
Me.OrderBy = me.Status.Value = Waiting
 
my one question i want to sort my table by the status when its "Waiting"

That doesn't make sense. OrderBy sorts by a column, if you sort by a column that has all the same values then there's nothing to sort:

"Here's a list of everyone in the Accounting Department, sort it by the department they are in"

Well, that's not possible because when you sort "Accounting, Accounting, Accounting..." there's no point. Now, if we had a list of everyone we could first sort by their department then their last name and then even their first name and then whatever fields you wanted. But if you are sorting by just one field and that field is the same for everyone, your not doing any sorting.


Perhaps you can better demonstrate your issue with data. Show us some sample data and how you would like it ordered.
 
of course see attached
 

Attachments

  • order.png
    order.png
    20.5 KB · Views: 147
That doesn't completely help. What do you want to occur with that data?
 
sorry just added the image and forgot the text

ok on open of the form they would like the status which are waiting to the top
 
ok great hopefully last post by me on this subject, that docs for access 2007 will it work in 2010
 
sorry i lied about being last post

have also just seen about using a query

which is here (well attached)

and have this code in form load but it seem's to work as good as a chocolate teapot i.e not at all

Code:
DoCmd.OpenQuery "SortQuery"
 

Attachments

  • query.png
    query.png
    7 KB · Views: 151
I don't understand. What results does that query produce? How is it wrong?
 
it dosent sort as i expect it has done in the middle of waiting
 

Attachments

  • still.png
    still.png
    8.4 KB · Views: 110
That last image shows you are sorting by STartTime in descending order. You need to remove that.
 
ok yes sorry done that the query works fine but why does it not update the table on view or do i need to put in me.requery ?
 
I'm lost. Update what table? Me.requery is VBA and does not work from a query. What exactly are you trying to do?
 
on load of the main form i would like it if possible to filter the statues so all the waiting ones are shown first ( even though i think its a tad silly)
 
I think you are getting confused with a forms/reports sort order and a table view that is sorted.

Forms and reports generally use a sort order, tables shouldn't.

Just because you see the data in one order on a form does not mean the underlying tables data is stored that way. In fact the order of data in a table is effectively irrelevant and meaningless and certainly shouldn't be relied on. That's why you display unsorted table data on sorted and filtered forms and reports.
 

Users who are viewing this thread

Back
Top Bottom