• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

Add an index to a table in another Access database

From an Access database I create another database and export tables to it. The tables I am exporting are linked in from a backend. To do this I use the following SQL:

"SELECT * INTO myNewTable IN myNewDb FROM myOldTable"

This works fine, except that the newly-created table has no indexed fields. Once the table has been created in the new database I try to create the indexes using this:

"CREATE INDEX myIndex ON myNewTable (myField) IN myNewDb"

It doesn't work. Any ideas?
0
TimHudspith
Asked:
TimHudspith
1 Solution
 
Pratima PharandeCommented:
Please refer the link
http://www.brainbell.com/tutorials/ms-office/Access_2003/Indexing_A_Field.htm

here you will get the tutorial for adding index for the field.
try this..will help you
0
 
Bill RossCommented:
Hi,

I use the following DAO code to add an index.  Note you may want to modify the with statement depending on the type of index:

Public Function AddIndex()
    Dim tdf As DAO.TableDef, fld As DAO.Field, idx As DAO.Index
   
 'create index on MyField in MyTable
    Set tdf = CurrentDB.TableDefs("MyTable")
    Set idx = tdf.CreateIndex("MyFieldIdx")

'Note:  MyFieldIdx is just the index name - can be anything unique

    With idx
        .Fields.Append .CreateField("MyField")
        .Unique = False
        .Primary = False
    End With
    tdf.Indexes.Append idx

    db.TableDefs.Append tdf
   
    Set idx = Nothing
    Set fld = Nothing
    Set tdf = Nothing
   
End Function

Regards,

Bill
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now