Article ID: 199005
Article Last Modified on 6/23/2005
Sub CreateTables()
Dim ADOCon As New ADODB.Connection
Dim ADOCmd As New ADODB.Command
Dim MyStr As String
Dim i As Integer, j As Integer
' Use active Access connection.
Set ADOCon = CurrentProject.Connection
For i = 1 To 20
ADOCon.Execute "CREATE TABLE tblTest" & i
For j = 1 To 200
ADOCon.Execute "ALTER TABLE tblTest" _
& i & " ADD Field" & j & " Text"
Next
Next
Application.RefreshDatabaseWindow
End Sub
?FileLen(CurrentDb.Name)Note that this function returns the file size in bytes of the currently opened database (Northwind.mdb). Take note of the current size.
Option Explicit
Sub ADOX_CreateTables()
Dim cat As New ADOX.Catalog
Dim conn As New ADODB.Connection
Dim tbl As New ADOX.Table
Dim i As Integer, j As Integer
Set conn = CurrentProject.Connection
Set cat.ActiveConnection = conn
For i = 1 To 20
With tbl
'Create a new table
.Name = "tblTest" & i
'Add 200 text fields
For j = 1 To 200
.Columns.Append "Field" & j, adVarWChar, 50
Next j
End With
'Append the table into the Catalog's tables collection
cat.Tables.Append tbl
Set tbl = Nothing
Next
Application.RefreshDatabaseWindow
End Sub
ADOX_CreateTablesNote that twenty tables are added to the database, each with two hundred fields.
?FileLen(CurrentDb.Name)Note that the size of the Northwind.mdb file is now is significantly greater.
?FileLen(CurrentDb.Name)Note that the size of the Northwind.mdb file after compacting is now closer to the size that you saw on step 4.
Additional query words: pra
Keywords: kbbug kbnofix kbusage KB199005