Results 1 to 6 of 6
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69

    Set a tableDef Property

    Hi all,


    Using Access 365 and trying to set a table property.
    I have created a table with "CREATE TABLE..." sql statement. Now I need to set the "Order By" property of the newly created table to the sort order. I am using the below code:

    Dim table As DAO.TableDef
    Set table = Dbs.TableDefs("Tbl_Conversion")
    table.Properties("orderby") = "Empname, FCDNumber"

    When this code runs, I get an error message "Property not Found" or "Object doesn`t support this property or method|".

    Any suggestions?

    Thanks
    Deon

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Tables don't have a sort order, they are unsorted buckets that randomly hold data.
    Queries can have a sort order and if you need to see data in a specific order you should be using a query.

    Access will, by default, sort a table on the Primary Key if it has one, but don't rely on this as it's not guaranteed.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Some properties are created automatically when an object such as a table is created. Others don't exist until they are used. which explains the 'property not found' message. So you need to create them first. As to whether 'orderby' is a valid property name, I wouldn't like to say. check the properties of an existing table to see what it is called.

    And it may be that even if you create the property, it may be it cannot be modified with code.

    Either way, it won't be applied to a viewed table unless you click the filter button at the bottom of the datasheet, or also set the order by on load property to yes.

    Finally, opening a query/form/report based on the table will not apply the filter since the filter only applies when opening the table directly. You either need to set the sql to order as required, or set the orderby and order by on load properties of the query/form/report

    In summary, as a means of managing order, it has very limited use

  4. #4
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69
    Thanks all. What the intent is that I need to export the data to Excel in a specific sort order, but instead I opened the Excel file after the export action and sorted the data with code.

    Thanks
    Deon

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You can achieve the same, probably with less steps, just use a sorted query as the source for the Excel export.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You can achieve the same, probably with less steps, just use a sorted query as the source for the Excel export.
    I agree, and would suggest that tables don't have a sort order - fields have the sort order?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-09-2021, 05:52 PM
  2. What Property is this?
    By Lou_Reed in forum Access
    Replies: 7
    Last Post: 04-26-2017, 01:19 PM
  3. Double frondend to backend links following tabledef
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 06-15-2013, 09:10 PM
  4. TableDef assignation - Error 3420
    By Rod in forum Programming
    Replies: 1
    Last Post: 10-23-2012, 12:09 AM
  5. Strange TableDef behaviour
    By tym in forum Access
    Replies: 12
    Last Post: 11-24-2011, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums