Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to create table from SQL statement
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00260379
Message ID:
00260630
Views:
26
Use the "Create Table" SQL query. It will be a lot easier for you to port your application to something else than DAO later.

This sample is taken from MS-Access help.

This example creates a new table called ThisTable with two Text fields.

Sub CreateTableX1()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Create a table with two text fields.

dbs.Execute "CREATE TABLE ThisTable " _
& "(FirstName TEXT, LastName TEXT);"

dbs.Close

End Sub

This example creates a new table called MyTable with two Text fields, a Date/Time field, and a unique index made up of all three fields.

Sub CreateTableX2()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Create a table with three fields and a unique
' index made up of all three fields.
dbs.Execute "CREATE TABLE MyTable " _
& "(FirstName TEXT, LastName TEXT, " _
& "DateOfBirth DATETIME, " _
& "CONSTRAINT MyTableConstraint UNIQUE " _
& "(FirstName, LastName, DateOfBirth));"

dbs.Close

End Sub

This example creates a new table with two Text fields and an Integer field. The SSN field is the primary key.

Sub CreateTableX3()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Create a table with three fields and a primary
' key.
dbs.Execute "CREATE TABLE NewTable " _
& "(FirstName TEXT, LastName TEXT, " _
& "SSN INTEGER CONSTRAINT MyFieldConstraint " _
& "PRIMARY KEY);"

dbs.Close

End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform