G
Guest
Hello, i am using ADOX + VB .NET to create a Access Database
programmatically. I plan to set some properties of the column such primary
key.
The code is as follows:
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim idx As ADOX.Index
Dim prp As ADOX.Property
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
With tbl
..Name = "tblExperimental"
..ParentCatalog = cat
..Columns.Append "CustID", adInteger
..Columns("CustID").Properties("Autoincrement") = True
..Columns("CustID").Properties("Increment") = CLng(3)
..Columns("CustID").Properties("Seed") = CLng(2004000)
..Columns.Append "Name", adVarWChar, 5
..Columns("Name").Properties("Nullable") = True
..Columns.Append "Rating", adInteger
..Columns("Rating").Properties("Description") = "Customer Rating"
..Columns("Rating").Properties("Jet OLEDB:Column Validation Text") = "Must be
between 1 and 10"
..Columns("Rating").Properties("Jet OLEDB:Column Validation Rule") = ">0 and
<11"
..Columns("Rating").Properties("Default") = 5
End With
cat.Tables.Append tbl
Set idx = New ADOX.Index
With idx
..Name = "PrimaryKey"
..Columns.Append "CustID"
..PrimaryKey = True
..Unique = True
End With
tbl.Indexes.Append idx
Set idx = Nothing
Set cat = Nothing
when I run the program, it always issue some error: type is invalid.
Can anyone tell me how should I correct my code?
programmatically. I plan to set some properties of the column such primary
key.
The code is as follows:
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim idx As ADOX.Index
Dim prp As ADOX.Property
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
With tbl
..Name = "tblExperimental"
..ParentCatalog = cat
..Columns.Append "CustID", adInteger
..Columns("CustID").Properties("Autoincrement") = True
..Columns("CustID").Properties("Increment") = CLng(3)
..Columns("CustID").Properties("Seed") = CLng(2004000)
..Columns.Append "Name", adVarWChar, 5
..Columns("Name").Properties("Nullable") = True
..Columns.Append "Rating", adInteger
..Columns("Rating").Properties("Description") = "Customer Rating"
..Columns("Rating").Properties("Jet OLEDB:Column Validation Text") = "Must be
between 1 and 10"
..Columns("Rating").Properties("Jet OLEDB:Column Validation Rule") = ">0 and
<11"
..Columns("Rating").Properties("Default") = 5
End With
cat.Tables.Append tbl
Set idx = New ADOX.Index
With idx
..Name = "PrimaryKey"
..Columns.Append "CustID"
..PrimaryKey = True
..Unique = True
End With
tbl.Indexes.Append idx
Set idx = Nothing
Set cat = Nothing
when I run the program, it always issue some error: type is invalid.
Can anyone tell me how should I correct my code?