Jun 11 2022 02:30 PM
Procedure compiles correctly but gives the following error:
Run time error 3409
Invalid field definition "PrimaryIndex" in definition of index.
Instruction flagged:
tdfMenu.Indexes.Append idxPrimary
What am I doing wrong?
Public Sub CreateTable()
Const strTableName As String = "NewTable"
Dim dbMe As Database
Dim tdfMenu As TableDef
Dim idxPrimary As Index
Set dbMe = CurrentDb
Set tdfMenu = dbMe.CreateTableDef(strTableName)
With tdfMenu
.Fields.Append .CreateField("key", dbLong)
.Fields.Append .CreateField("Option", dbText)
.Fields("key").Required = True
.Fields("key").AllowZeroLength = False
.Fields("key").Attributes = dbAutoIncrField
.Fields("Option").Required = True
.Fields("Option").AllowZeroLength = False
End With
dbMe.TableDefs.Append tdfMenu
Set idxPrimary = tdfMenu.CreateIndex("PrimaryIndex")
With idxPrimary
.Fields.Append idxPrimary.CreateField("PrimaryIndex")
.Primary = True
End With
tdfMenu.Indexes.Append idxPrimary
End Sub
Jun 12 2022 02:31 AM
SolutionJun 12 2022 02:31 AM
Solution