Solved

Multiple fields in OrderBy (VBA)

Posted on 2008-10-27
5
699 Views
Last Modified: 2012-05-05
Hi Everyone,
Is it possible to have multiple sort criteria in an "OrderBy" statement?  I would like to sort first by date, then by time, but when I try to add time to my code, I get an "expected end of statement" error.
I tried ... OrderBy = "Date", "Time" when I received the error.
This is what I have now, but it does not sort by time:
...
JobTrailerSummaryTable_subform.Visible = True
JobTrailerSummaryTable_subform.Form.OrderBy = "Date"
JobTrailerSummaryTable_subform.Form.OrderByOn = True
...

Any Ideas?
0
Comment
Question by:Andy419
  • 3
5 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 22817033
JobTrailerSummaryTable_subform.Visible = True
JobTrailerSummaryTable_subform.Form.OrderBy = "Date, Time"   ' separate by comma
JobTrailerSummaryTable_subform.Form.OrderByOn = True
0
 
LVL 75
ID: 22817044
You may need brackets also:


JobTrailerSummaryTable_subform.Form.OrderBy = "[Date], [Time]"   ' separate by comma
0
 

Author Closing Comment

by:Andy419
ID: 31510531
THANKS -- That was it!!!
0
 
LVL 8

Expert Comment

by:fabriciofonseca
ID: 22817050
You can do it using SQL but my suggestion is always to build a form upon a query, thus you can go to the query and easily filter or order by and it will be automaticaly reflected into the form.


Regards
0
 
LVL 75
ID: 22817051
Also ... not a good idea to have field names such as Date and Time, since these are Access Reserved Words.

mx
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sort Time by AM and PM in query 2 21
ms/access hyperlink/ftp 7 39
Query to summarise data Like Pivot Table 3 29
Access coding 2 15
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now