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

Variable Table Name For A Query

Hi,

I'm a novice Access user and have a simple question but can't seem to find the answer.
I have tables imported and named by the user on import e.g. January.
I then need to run a query on the table that the user selects (same query and each table is in the same format so the fields are known).
I have a combo box on the form for the user to select the table on which to perform the query. It's just the table name which is the variable i need to insert into my query.

My SQL for this looks like:
Expand|Select|Wrap|Line Numbers
  1. SELECT field1, field2
  2. FROM Forms!Form1!Combo1
I've tried enclosing with ( ) , [ ] , " " , ' ' , & & but keep getting errors.
Syntax error in FROM clause
or
Cannot find the input table / query 'Forms!Form1!Combo1' make sure it exists.

I'm sure someone will know the answer...
Thank you
Feb 17 '08 #1
2 2694
Scott Price
1,384 Expert 1GB
Is this in a standard query, or written into VBA code?

In VBA code the syntax would be: "Select [Field1], [Field2] From " & Forms!Form1.Combo1 & ";"

However, you need to make sure that the combo box in question has as it's bound column the actual name of the table you wish to select from. If the combo box is bound to an invisible column containing a number value, your select statement will be looking for a table with the 'name' of that number value.

Regards,
Scott
Feb 17 '08 #2
NeoPa
32,556 Expert Mod 16PB
As Scott says, it's hard to know what to suggest if you don't say how you're expecting to run the query code you're referring to.
What VBA code are you using at the moment?
Feb 22 '08 #3

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

Similar topics

8
by: Adrian Parker | last post by:
Hi. I would like to query a database, given several where clauses to refine my search, and return the value of one single field in the database. eg: I have a table that lists teachers. Their...
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
1
by: Greg | last post by:
How can I use a variable as the table name?
4
by: Andre Arpin | last post by:
I am new at sql so would appreciate some help I have the name of a table in alocal variable is it possible to select this table DECLARE @name sysname SET @name = 'tblSniffedItems' PRINT...
4
by: Henro V | last post by:
I want the login name that somebody enters when starting the database to be set as a variable. I'll try to explain: I have a table (Engineer) that lists engineers (they are the users) The...
4
by: dixie | last post by:
I want to write a query where one of the two tables in it is variable and its name is picked up from a text box control on an open form. The query is very simple and is only a select query with...
1
by: stephane | last post by:
I have a problem which must be in this : print" <script type='text/javascript'> document.location.replace('http://127.0.0.1/add_task.php?req_id={$maxValue}&tk_request_name={$req_name}');...
2
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
2
by: keeps21 | last post by:
I have a script that recieves an id number via the address bar when a link is clicked. ie . index.php?id=1 if the link was for the story whose ID is 1. My script checks if a user is logged in,...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.