Setting unique index

J

Jan Kr

Hi NG!

I have two databases, ie Db1.mdb and Db2.mdb. Db2.mdb contains a table, Tbl1
with a field, id Field1.

My question is, can I - using VBA in a module in DB1.mdb - set Field1 in
Tbl1 in Db2 to be Indexed wíth no duplicates?

Jan
 
T

TPratt

Yes:

Dim Db as Database
Dim tdf as TableDef
Dim idx as Index
Dim fld as Field

Set Db = DBEngine.Workspaces(0).OpenDatabase("Path to database.mdb")

Set tdf = Db.TableDefs("Name of Table")
Set idx = tdf.CreateIndex("Primary")

idx.Primary = True

Set fld = idx.CreateField("Name of the Field in your table")

idx.Fields.Append fld

tdf.Indexes.Append idx


Works like a charm!
 

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