?
Solved

Weird Problem with SQL CREATE TABLE?

Posted on 2002-07-16
11
Medium Priority
?
212 Views
Last Modified: 2010-05-02
Hello, I am working on a program that basicly creates a database and I am having problems using the SQL CREATE TABLE to make the tables. The database that I am using is Access (DAO 3.6). Here is a piece of code:
 Set DB = engine.CreateDatabase(txtDatabasePath.Text, dbLangGeneral)
 
  DB.Execute "CREATE TABLE keys (test varchar(10) NOT NULL, ver varchar(1) default 'A', answers varchar(60) NOT NULL)TYPE=MyISAM;", dbFailOnError
  DB.Execute "CREATE TABLE answers (sID varchar(2) NOT NULL, pID varchar(3) NOT NULL, comp_ans varchar(60) default NULL, math_ans varchar(60) default NULL, sci_ans varchar(60) default NULL)TYPE=MyISAM;", dbFailOnError

Is there something wrong that I am missing. I thought for sure that you could do this, but maybe I was mistaken. Thanks a lot for the help.
~evlich
0
Comment
Question by:Evlich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 7157738
The 'TYPE=MyISAM' is not an Access command - it is specific to MySQL.  Try removing that first.

Default is also problematic in Access.  As of Access 97, Default is not accepted as a legal command, but this may have changed in Access 2000.

The default NULL statements can be left off - Access will default to NULL for fields.
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157788
Do you have to use DAO?  It's much easier using ADO and ADOX.  I can even supply an example if you want to get out of the dark ages...I mean away from DAO.
0
 
LVL 1

Author Comment

by:Evlich
ID: 7157946
Well the defaul let me get through those first tow lines, but I have several more line that it is getting trapped on. Can you use tinyint and stuff like that? Here is the new line that the program gets trapped on:
  DB.Execute "CREATE TABLE prog_submissions (tID TINYINT(2) NOT NULL, problem varchar(5) NOT NULL, correct TINYINT(1) NOT NULL, time TIME NOT NULL, er_code tinyint(1));", dbFailOnError
There are still a few lines after that, but I think that this has all the stuff that is used later on. Thanks a lot.
~evlich
P.S. I would appreciate some links to pages for ADO, I have never actually used it, and it might be better for this.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7157974
Her's a module to create a DB:
Public Function gfAB_CreateDB(asDB as string) As Boolean
    Dim adoxCat     As ADOX.Catalog
   
    On Error Resume Next
   
    If Len(Dir(asDB)) > 0 Then Kill asDB
   
    On Error GoTo Syntax_Error
   
    Set adoxCat = New ADOX.Catalog
   
    adoxCat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    Set adoxCat = Nothing
    gfAB_CreateDB = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateDB = False
    Resume Exit_Sub

End Function

Here's a function to create a table:
Public Function gfAB_CreateTable(asDB as string) As Boolean
    Dim adoxCat     As New ADOX.Catalog
    Dim adoxTab     As New ADOX.Table
    Dim adoxCol     As ADOX.Column
   
    On Error GoTo Syntax_Error
   
    adoxCat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & asDB
   
    adoxTab.Name = "TableNameHere"
   
    Set adoxCol = New ADOX.Column
    adoxCol.Name = "ColNameHere"
    adoxCol.Type = adVarWChar
    adoxCol.DefinedSize = 2
    adoxCol.Attributes = adColNullable
    adoxTab.Columns.Append adoxCol
   
    adoxCat.Tables.Append adoxTab
   
    Set adoxCol = Nothing
    Set adoxTab = Nothing
    Set adoxCat = Nothing
   
    gfAB_CreateTable = True
   
Exit_Sub:
    Exit Function
   
Syntax_Error:
    gfAB_CreateTable = False
    Resume Exit_Sub

End Function


The above would create a table with one varchar(2) column.

Hope that helps.
Steve

PS  Don't forget to add a reference to the ado ext.
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 7158004
Tinyint(2) - I assume that this is a 2 byte integer?

Here are some Access SQL Conversions for you:

4 byte integer, usually INT or INTEGER in most SQL dialects.  Access SQL = INTEGER

2 byte integer, usually smallint in most SQL dialects.  Access SQL = smallint or integer2

1 byte integer, usually tinyint in most SQL dialects.  Access SQL = integer1 or byte



0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7158013
nope it will create a varchar(2)
this will creat an integer column:
    adoxCol.Type = adInteger
0
 
LVL 1

Author Comment

by:Evlich
ID: 7158651
Well, that worked, only one more problem, how do you do a date/Time field.
~evlich
0
 

Expert Comment

by:Amitabh
ID: 7158881
Following is a link for creating database through ADOX and learning other features.

http://www.able-consulting.com/ADOX_Faq.htm#Q2

regards,
A. Pandey
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 7159232
I don't know if you are asking me but here's what to use for dates and times:
adoxCol.Type = adDBDate
adoxCol.Type = adDBTime
adoxCol.Type = adDBTimeStamp
0
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 200 total points
ID: 7159869
For SQL creation, use DATETIME - Alternates are DATE or TIME - all reate an Access DateTime field
0
 
LVL 1

Author Comment

by:Evlich
ID: 7162618
Thanks a lot. I appreciate all the help and suggestions that I was given by everyone. I will take ADO into consideration.
~evlich
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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