Results 1 to 7 of 7
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Drop all indexes from table

    I know you can do it individually with:

    DoCmd.RunSQL "DROP INDEX [ColumnName] on TableName" with the only change being ColumnName



    DoCmd.RunSQL "DROP INDEX * on TableName;" or
    DoCmd.RunSQL "DROP INDEX $ on TableName;" gets Runtime Error 3295

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    design table, set field index to no, save.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I am importing an excel file via DoCmd.TransferSpreadsheet 0, 9, "Temp", strFile, 1

    Then I am dropping many columns and some have indexes and will not delete. Thus I have to drop indexes with
    DoCmd.RunSQL "DROP INDEX [ColumnName] on TableName", there are 12 indexes, thus 12 lines of the same code with differing column names.

    I am looking at the transferspreadsheet to not import indexes, or be able to remove all indexes at once. Dropping indexes and columns is not a necessary step, but would like to know.



  4. #4
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    As far as I'm aware transfer spreadsheet won't create an index.
    It would only utilize one if the table being imported to already had one?

    So modifying your table would only need doing the once, so not much need to do it with code?
    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 ↓↓

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I have the code made up to delete the indexes, but it adresses each individual one. I was trying to find a wildcard type way an minimize code.

  6. #6
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Create a make table query from the existing one, no indexes would be created, then delete the original one and rename the new table.

    I still can't really see the need to automate a one off process.
    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 ↓↓

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I was trying to find a wildcard type way
    I don't think so (taken literally) but to try to answer that from the point of coding, I'd say only by looping each field in a table and testing if it has an index before attempting to delete it (as opposed to just attempting to delete and handling the resulting error). Then again, there's no substitute for minimizing code by not using it at all when not necessary.
    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: 4
    Last Post: 06-16-2015, 03:53 AM
  2. Table Indexes
    By Joetoben in forum Queries
    Replies: 1
    Last Post: 05-21-2015, 12:14 PM
  3. Need to update ODBC table with too many indexes
    By RandV in forum Programming
    Replies: 4
    Last Post: 11-19-2014, 01:08 PM
  4. Indexes in a Table
    By FB93 in forum Access
    Replies: 2
    Last Post: 03-18-2014, 07:27 PM
  5. Table Indexes
    By AnthonyT in forum Access
    Replies: 3
    Last Post: 06-04-2009, 06: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