Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The following Visual Basic for Applications example creates in the current database a table with some of the common data types and properties, such as AutoNumber, Decimal, Memo, and Text.
NOTE: Before you run the code, click
References on the
Tools menu, and make sure that you have the following reference selected:
Microsoft ADO Ext. 2.x for DDL and Security
Sub ADOX_CreateJetTable()
'This example demonstrates creating a Jet table with
'Autoincrement, Decimal, and Memo columns.
Dim tbl As New ADOX.Table
Dim cat As New ADOX.Catalog
'Return Reference to current database.
Set cat.ActiveConnection = CurrentProject.Connection
'Assign the new table name.
With tbl
.Name = "MyNewTable"
' Append new columns to the table.
With .Columns
.Append "MyID", adInteger
.Append "MyMemo", adLongVarWChar
.Append "MyVarChar", adWChar, 50
.Append "MyDecimal", adNumeric
'After appending columns, set
'provider specific properties.
With !MyID
Set .ParentCatalog = cat
.Properties("Autoincrement") = True
.Properties("seed") = CLng(20)
.Properties("increment") = CLng(20)
End With
With !MyDecimal
Set .ParentCatalog = cat
.Precision = 2
.NumericScale = 1
End With
With !MyVarChar
Set .ParentCatalog = cat
.Properties("Jet OLEDB:Compressed " _
& "UniCode Strings") = True
End With
End With
End With
' Append new table to the provider catalog and clean up.
cat.Tables.Append tbl
Set cat = Nothing
End Sub