Creating a table from within a Module in MS access

  • Thread starter Thread starter CES
  • Start date Start date
C

CES

All,
I have been searching for a simple example, or any example for that matter, of how one would create a table from a Module and not from a Make Table Query. If anyone knows of such a beast I would greatly appreciate the URL. Thanks in advance. - CES
 
You could also use DAO or ADOX.

For examples of using DAO, check the CreateTableDef, CreateField,
CreateIndex and CreateRelation methods in the Help file.

For ADOX, you need to declare objects as Table, Column, Index or Key, set
their properties appropriately, and append them to the appropriate
collection.
 
Douglas said:
You could also use DAO or ADOX.

For examples of using DAO, check the CreateTableDef, CreateField,
CreateIndex and CreateRelation methods in the Help file.

For ADOX, you need to declare objects as Table, Column, Index or Key, set
their properties appropriately, and append them to the appropriate
collection.

Thank you... I'm in the process of working through a couple of examples that I was able to paste together based on the CREATE TABLE statement. -- CES

Dim tmp As String
tmp = "TempTable"

Dim cmd As ADODB.Command
Dim strSQL As String


Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText


'create New Table
strSQL = "CREATE TABLE " & tmp & " (Field1 TEXT, Field2 TEXT, Field3 TEXT);"
cmd.CommandText = strSQL
cmd.Execute

' refresh database window
Application.RefreshDatabaseWindow


Set cmd = Nothing
 
Douglas said:
You could also use DAO or ADOX.

For examples of using DAO, check the CreateTableDef, CreateField,
CreateIndex and CreateRelation methods in the Help file.

For ADOX, you need to declare objects as Table, Column, Index or Key, set
their properties appropriately, and append them to the appropriate
collection.

Thank you... I'm in the process of working through a couple of examples that I was able to paste together based on the CREATE TABLE statement. -- CES

Dim tmp As String
tmp = "TempTable"

Dim cmd As ADODB.Command
Dim strSQL As String


Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText


'create New Table
strSQL = "CREATE TABLE " & tmp & " (Field1 TEXT, Field2 TEXT, Field3 TEXT);"
cmd.CommandText = strSQL
cmd.Execute

' refresh database window
Application.RefreshDatabaseWindow


Set cmd = Nothing
 
Back
Top