|
-
May 22nd, 2000, 09:22 PM
#1
Thread Starter
New Member
I would like to know how to create tables within VB Code. The user will be allowed to create tables within the application interface. I have been reading about ADO objects. you can use this object to create recorsets, connection, and commands but how can use it to create tables on an Access.MDB File.
-
May 22nd, 2000, 09:35 PM
#2
Lively Member
Once you've opened a connection to the database e.g.
Code:
cn.Open ConnectionString, UID, PWD, Options
use cn.Execute to create the table with SQL - for example to create a table called "Toot" with fields "ID" (long int - primary key), and "Name" (String), use the following (untested)
Code:
cn.Execute "CREATE TABLE Toot (ID long NOT NULL, Name String NOT NULL, CONSTRAINT pk PRIMARY KEY(ID))"
Don't forget that if you want to make ID an auto-increment field it's an attribute but I can't remember exactly how to do it - search the database forum for autonumber and attribute if you're interested.
HTH,
Toot
Some cause happiness wherever they go; others, whenever they go.
-
May 24th, 2000, 01:02 PM
#3
PowerPoster
Use Microsoft ADO Ext. 2.1 for DDL and Security reference
Sure this the solution that you looking for.
Code:
Sub CreateTable()
Dim tbl As New Table
Dim cat As New ADOX.Catalog
'Open the catalog.
' Open the Catalog.
cat.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|