473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How Can I create a table by specifying tablename via inputbox

106 100+
Hi

my application creates a table using this code:
Expand|Select|Wrap|Line Numbers
  1.     strSql = "CREATE TABLE Output (Name Text, Month Number)"
  2.  
  3.     DoCmd.RunSQL strSql
  4.  
I need to change the table name 'Output' by a name specified via inputbox, but i'm not sure how it can be achieved.
(something to this effect but it does not work)
Expand|Select|Wrap|Line Numbers
  1.     DIM tblName As String
  2.     DIM strSql As Strng
  3.  
  4.     tblName=InputBox("Table Name")
  5.     strSql = "CREATE TABLE '" & Output & "' (Name Text, Month Number)"
  6.  
  7.     DoCmd.RunSQL strSql
  8.  
Sep 3 '10 #1

✓ answered by TheSmileyCoder

Expand|Select|Wrap|Line Numbers
  1.     tblName=InputBox("Table Name") 
  2.     strSql = "CREATE TABLE " & tblName & " (Name Text, Month Number)" 

4 1722
TheSmileyCoder
2,322 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1.     tblName=InputBox("Table Name") 
  2.     strSql = "CREATE TABLE " & tblName & " (Name Text, Month Number)" 
Sep 3 '10 #2
TheSmileyCoder
2,322 Expert Mod 2GB
You should consider adding some error handling code, in case user specifies an invalid table name, a blank string (closes inputbox wihtout typing anything) and so on.
Sep 3 '10 #3
tasawer
106 100+
Hi Thank you for the suggestion.

obvioulsy my error was on using the apostrophe.

I am confused towards using the apostrophe in sql.
How can I know When to use it and when not to use it.
Sep 3 '10 #4
missinglinq
3,532 Expert 2GB
Our exalted leader, NeoPa, has an excellent tutorial on that very subject in the Insights section:

http://bytes.com/topic/access/insigh...-when-use-them

Linq ;0)>
Sep 3 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew | last post by:
I have a problem creating mySQL tables with PHP. I am making an app where a user can create a project. Pressing "submit" on proj_form.php goes to proj_add.php where a couple of things happen. ...
3
by: J West | last post by:
Warning: Error while executing this query:CREATE TABLE "purchaseorder" ( "PurchaseOrderID" int(10) unsigned NOT NULL auto_increment, "PurchaseCost" double unsigned zerofill NOT NULL default...
4
by: Michael Jackson | last post by:
I have a stored procedure to create a table. In my program I want the user to name the table to be created, therefore I pass a parameter to the SP for the table name. I cannot get it to work. It...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
1
by: Jack Miller | last post by:
Hi, Is there any SQL command in Oracle that returns a "CREATE TABLE" statement in Oracle. For example in MySQL there is a command called "SHOW CREATE TABLE <tableName>" This command can be...
9
by: Jack Miller | last post by:
Hi, Is there any SQL that would return the "CREATE TABLE" statement for an existing table in the database? Regards, Jack
12
by: ilya_slutsker | last post by:
I am having error trying to run some mysql script (back from 2001). It gives me the error like : ERROR 1067 (42000) at line 48: Invalid default value for 'log_id' in the statement : CREATE...
3
by: smitashirole | last post by:
can we create table with tablename as TABLE eg. create table TABLE(no int ,name varchar(20)); like this.
4
by: Priya | last post by:
Hey all, Is there a way to create a table in the SQL database by using an XML file as an input? I want to have an XML file which holds all the details of the table like the tablename, columns,...
1
by: indhian | last post by:
i need to create table programatically, without specifying in aspx page.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.