Add Index Property To Temp Table

  • Thread starter Larry R Harrison Jr
  • Start date
L

Larry R Harrison Jr

I have Access 97. I have a "tmp" table that is created in code via a query
(or SQL statements), I then need to modify 2 of the fields to be index (dups
okay). I cannot for the life of me figure out how to do this in code.

The field is "Approved", it's a YES/NO field, the table is "tmpTable."

How do I do this?

LRH
 
B

Brendan Reynolds

The commented out lines are the lines I used to create the table. You don't
need them because, of course, the table already exists in your database ...

Public Sub AddIndex()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index

Set db = CurrentDb
'Set tdf = db.CreateTableDef("tmpTable")
Set tdf = db.TableDefs("tmpTable")
'Set fld = tdf.CreateField("Approved", dbBoolean)
'tdf.Fields.Append fld
'db.TableDefs.Append tdf
Set idx = tdf.CreateIndex("Approved")
Set fld = idx.CreateField("Approved", dbBoolean)
idx.Fields.Append fld
tdf.Indexes.Append idx

End Sub
 
L

larrytucaz

Brendan said:
The commented out lines are the lines I used to create the table. You don't
need them because, of course, the table already exists in your database ...

Public Sub AddIndex()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index

Set db = CurrentDb
'Set tdf = db.CreateTableDef("tmpTable")
Set tdf = db.TableDefs("tmpTable")
'Set fld = tdf.CreateField("Approved", dbBoolean)
'tdf.Fields.Append fld
'db.TableDefs.Append tdf
Set idx = tdf.CreateIndex("Approved")
Set fld = idx.CreateField("Approved", dbBoolean)
idx.Fields.Append fld
tdf.Indexes.Append idx

End Sub
Thanks for the code. I did fortunately find some earlier in Google
archives. The part that throws/confuses me is the Set fld=.createfield
(etc) because the field in question already exists.

LRH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top