• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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