?
Solved

Create New Table in MDB database

Posted on 2007-07-25
5
Medium Priority
?
156 Views
Last Modified: 2010-04-09
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
0
Comment
Question by:Takamine334
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Anthony2000
ID: 19571591
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
 
LVL 7

Accepted Solution

by:
ravs120499 earned 1500 total points
ID: 19573605
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
 

Author Comment

by:Takamine334
ID: 19577640
if I wanted ID to be an autonumber, what datatype would I use?
0
 
LVL 7

Expert Comment

by:ravs120499
ID: 19586270
Have you tried Autonumber as the type?
0
 

Author Comment

by:Takamine334
ID: 19590534
It's autoincrement
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question