473,324 Members | 2,248 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,324 software developers and data experts.

Variables as table names

Hello,
I have a database that asks the user for many inputs and stores them in variables. From these variables a table name is created. Like so:

Expand|Select|Wrap|Line Numbers
  1. 'Specify table name
  2.     Set tbl = dbs.CreateTableDef(userCircuit & "-" & userStart & "," & userEnd) 
Where userCircuit, userStart, and userEnd are all variables. I am attempting to add information to this table that is created by this statement:

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.RunSQL ("INSERT INTO Table1 ([Field1])VALUES(Cable_Start)") 
isnstead of "Table1" I want the table to be the table I created with the first set of code. I attempted to replace "Table1" with "userCircuit & "-" & userStart & "," & userEnd" but I get a syntax error. I have attempted many things and could not figure this out. I am sure it is something incredibly simple being that I have never worked with VBA before, but I just cant point it. Thank You!

My most current attempt I saved the 3 seperate variables into one string variable, so I end up with:
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.RunSQL ("INSERT INTO tableName([Field1])VALUES(Cable_Start)") 
so all that is left to be done is to figure out how to have it identifiy "tableName" as a variable instead of actually the word "tableName"
Seth
Aug 30 '10 #1
2 1342
Jerry Winston
145 Expert 100+
It's been awhile since I've touched VBA. Will this work?
Expand|Select|Wrap|Line Numbers
  1.  
  2.  Dim myCMDStr STRING
  3.  myCmdStr = "INSERT INTO [" & userCircuit & "-" & userStart & "," & userEnd & "] ([Field1])VALUES(Cable_Start)"
  4.  DoCmd.RunSQL (myCMDStr ) 
Aug 30 '10 #2
It seemed as though this worked! Thanks a million you saved me hours of aggravation. Just as a note to anyone else who may be encounting this problem I changed the above suggestion a bit just to work properly in my code. Thanks again!

Expand|Select|Wrap|Line Numbers
  1. Dim myCMDStr As String
  2.    myCMDStr = "INSERT INTO [" & userCircuit & "-" & userStart & "," & userEnd & "] ([Cable_Start])VALUES(Cable_Start)"
  3.    DoCmd.RunSQL (myCMDStr)
Aug 31 '10 #3

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

Similar topics

1
by: David | last post by:
Hi, I currently administer our MySQL db version 3.23.56 on a Linux Cobalt Qube server via an external fron-end piece of software. My Table Names have capital letters at the beginning, i.e....
2
by: ewu | last post by:
Hello all, I got a chance to peak into a database system. Part of its design is rather unfamiliar to me. When I look at the diagram generated by SQL Server, there are many floating tables. ...
1
by: php newbie | last post by:
I have a quick question on how to qualify table names as it relates to "dbo" vs. user names. Suppose that I am a user named "dwuser1", and that I need to create a table named "dw_stage_1". Do I...
1
by: Astra | last post by:
Hi All Found that when I executed my DDL script on a Win32 installation of MySQL (v4.0.18) it converted all of my table names to lowercase. The problem was that after I had filled the newly...
8
by: rong.guo | last post by:
Greetings! I am now doing one type of analysis every month, and wanted to creat table names in a more efficient way. Here is what happens now, everytime I do the analysis, I will create a...
1
by: Jens Riedel | last post by:
Hello, we are planning to port an application from one database to different others, including DB2. While reading the GettingStarted document for DB2 Personal Edition I got a little confused...
2
by: Brian O'Haire | last post by:
Hi I am trying to determine the column names in a table in an access xp database using c# in an asp.net web page. I can determine the table names by reading the MSysObjects table. The SQL system...
5
by: adi | last post by:
Hi all, Seems like a fundamental question to me but I dont have a definite answer for it, Gurus please enlighten me. I have a table 'Table1' whose structure changes dynamically based on some...
3
by: David C. Barber | last post by:
Using SQL Server 2000 and moving to a new computer. We did a full backup of the existing database to tape, brought up the new computer with a clean install using the same server name and IP...
1
by: Arne Gulbrandsen | last post by:
How to use Variables as Table Names in MS Access
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.