[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access SQL Create Table

Posted on 2013-06-18
8
Medium Priority
?
431 Views
Last Modified: 2013-06-20
Hi
I am trying to create a table with a Decimal column called "Test"
using the following code, but am getting a syntax error with:
[Test] DECIMAL (10,2),

CREATE TABLE tblTest
    (CustomerID INTEGER NOT NULL,
    [Test] DECIMAL (10,2),
    [First Name] TEXT(50) NOT NULL,
    Phone TEXT(10),
    Email TEXT(50))
0
Comment
Question by:Murray Brown
8 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39257741
You can use CURRENCY which should automatically give you 4 decimal places, or DOUBLE, or SINGLE.

If you want 2 decimal places, use the table field DecimalPlaces property, Format property, or the format function.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39257991
A field of type DECIMAL cannot be created in an Access database using DAO, but it can be done with ADO.

Instead of CurrentDb.Execute strDDL,
use CurrentProject.Connection.Execute strDDL

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
0
 

Author Comment

by:Murray Brown
ID: 39258711
Hi

Thanks. What would the full ADO code look like?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 20

Assisted Solution

by:GrahamMandeno
GrahamMandeno earned 1000 total points
ID: 39258825
You can't put the code in a query because that will execute using DAO.  Create a VBA module with code like this:

Public Sub MakeMyTable()
Dim strDDL as String
strDDL = "CREATE TABLE tblTest" _
    & " (CustomerID INTEGER NOT NULL," _
    & " [Test] DECIMAL (10,2)," _
    & " [First Name] TEXT(50) NOT NULL," _
    & " Phone TEXT(10)," _
    & " Email TEXT(50)) "
CurrentProject.Connection.Execute strDDL
End Sub

Open in new window

Then you can execute your procedure, either from some other VBA code, or from the Immediate window:
?MakeMyTable

-- Graham
0
 

Author Comment

by:Murray Brown
ID: 39258887
Hi

I should have mentioned that I am building this in VB.net/VSTO
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 39261713
I am building this in VB.net/VSTO
Then create an OleDbConnection and use the ExecuteNonQuery method to run the SQL that Graham provided:

Dim cmd As New System.Data.OleDbConnection
cmd.ConnectionString = "Your Access Connection"
cmd.Open

Dim strDDL as String
strDDL = "CREATE TABLE tblTest" _
    & " (CustomerID INTEGER NOT NULL," _
    & " [Test] DECIMAL (10,2)," _
    & " [First Name] TEXT(50) NOT NULL," _
    & " Phone TEXT(10)," _
    & " Email TEXT(50)) "

cmd.CommandText = strDDL
cmd.ExecuteNonQuery
0
 

Author Closing Comment

by:Murray Brown
ID: 39261753
Thanks very much. Should have realised that. Got into a tangle with all the different approaches on the net.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39261823
Thanks, Scott.  I've been out all day so I wasn't here to fill in the cracks :-)

Cheers,
Graham
0

Featured Post

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.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

834 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