Create New Table in MDB database

How do I create a table in a database from scratch using ADO code? I just want to have an inputbox with NewUSERDB as the string variable. That person will input a table name (ex. Portland, OR) and it'll create a table in a database (MDB) with the fields:

ID
Name
Age
Sex
City
State
Country
Birthday
Picture
Music
Last Login
Takamine334Asked:
Who is Participating?
 
ravs120499Commented:
Assume the table name is passed in the variable TblName
Dim SqlConn As ADODB.ConnectionClass
Dim sqlQuery As String

Set sqlConn = New ADODB.ConnectionClass

sqlConn.Open(<Connection string>)
sqlQuery = "create table " + TblName + " (ID <datatype>, Name <datatype> ...);"
sqlConn.Execute(sqlQuery, 0, 0)
sqlConn.Close

Similiarly, you can also use DML SQL statements to create indexes etc.
0
 
Anthony2000Commented:
I found this link, it contains many examples that demonstrate creating an mdb database and creating a table within it.

http://functionx.com/ado/Lesson06.htm
0
 
Takamine334Author Commented:
if I wanted ID to be an autonumber, what datatype would I use?
0
 
ravs120499Commented:
Have you tried Autonumber as the type?
0
 
Takamine334Author Commented:
It's autoincrement
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.