Example using ADOX.
'-- set reference to ADOX library
'- Microsoft ADO Ext. 2.6 for DDL and Security
'-- Microsoft ActiveX data objects 2.6 library also needed for ADO
Dim cg As New ADOX.Catalog
Dim tb As New ADOX.Table
Dim cn As adodb.Connection
Dim cl As ADOX.Column
Set cg.ActiveConnection = CurrentProject.Connection
'- create a test table.
tb.Name = "Test"
tb.Columns.Append "col1", adInteger
tb.Columns.Append "col2aa", adVarWChar, 50
Debug.Print "table = "; cg.Tables("Test").Name
cg.Tables.Append tb
'' modify the test table.
'-rename a column
Set tb = cg("test")
Set cl = tb("col2aa")
Debug.Print cl
'- modify a property of the column.
cl.Properties("Jet OLEDB:Allow Zero Length") = True
cl.Name = "col2bb"
Debug.Print cl
Set up a connection string to the Access.mdb from your program.
replace this with your connection.
Set cg.ActiveConnection = CurrentProject.Connection
Dim connString As String
Dim cn As New ADODB.Connection
connString = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\someserver\somedirectory\yourmdb.mdb;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString
Set cg.ActiveConnection = cn
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.