Is there any way to set the OrderBy property of a table using Visual Basic?
Is there any way to set the OrderBy property of a table using Visual Basic?

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
You should be able to set it using the TableDef collection - though I can't think of a reason to ever do it. That's the property that get's set when you sort a table on the fly, and only very rarely do we even let the user see the tables directly.
Wendell
I can't seem to find a way to do this for a table... Not with a simple VB statement anyway... The OrderBy and OrderByOn properties are available for forms and reports, but not tables (from what I can see... ) One way you could change the order temporarily would be to use an SQL statement with an Order By clause in your code......
Using DAO the code would look something like this...
Dim db as dao.database
Dim rst as dao.recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Select * From TableName Order By FieldName;")
I believe this would order it properly for you to work with but it's not going to be a permanent change to the table design...
HTH
What are you trying to accomplish? Tables are normally sorted by their primary key. If you want to present the data to your users, use a query and set the Order By in the SQL.
Charlotte