ACC2000: How to Create a Table with Jet Data Types via ADOX (275252)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q275252
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

SUMMARY

This article contains an ActiveX Extensibility Objects (ADOX) example that demonstrates a way to create a native Jet table with some of the common Jet data types and properties.

MORE INFORMATION

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
				

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbhowto KB275252