Option Explicit
Public Sub Create_DB()
Dim db As DAO.Database
Dim tb As TableDef
Dim fld As Field
Set db = DBEngine.CreateDatabase("c:\.mdb",
dbLangGeneral)
Set tb = db.CreateTableDef(""
' Create and append new Field objects for the new
' TableDef object.
With tb
' The CreateField method will set a default Size
' for a new Field object if one is not specified.
.Fields.Append .CreateField("", dbText, 10)
.Fields.Append .CreateField("", dbText, 50)
.Fields.Append .CreateField("", dbText, 5)
.Fields.Append .CreateField("", dbText, 50)
End With
db.TableDefs.Append tb
Set tb = Nothing
db.Close
Set db = Nothing
Call CreateIndexX
End Sub
Sub CreateIndexX()
Dim dbsMyDB As Database
Dim tdfUsers As TableDef
Dim idxUsername As Index
Set dbsMyDB = OpenDatabase("c:\.mdb"
Set tdfUsers = dbsMyDB!
With tdfUsers
' Create first Index object, create and append Field
' objects to the Index object, and then append the
' Index object to the Indexes collection of the
' TableDef.
Set idxUsername = .CreateIndex(""
With idxUsername
.Fields.Append .CreateField(""
'Create Primary Key
.Primary = True
End With
.Indexes.Append idxUsername
' Refresh collection so that you can access new Index
' objects.
.Indexes.Refresh
End With
dbsMyDB.Close
End Sub