473,657 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable Table Name For A Query

10 New Member
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!Co mbo1' make sure it exists.

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

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

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,568 Recognized Expert Moderator MVP
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
4807
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 first name, last name, age, unique teacher number, etc is in the file. I want to return the unique teacher number, for example, of the teacher whose first name is Jane and last name is Doe. How does one do this?
6
2742
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 = server.createobject("scriptlet.typelib").guid guid=Left(guid,instr(guid,"}")) genguid=guid
1
2531
by: Greg | last post by:
How can I use a variable as the table name?
4
6036
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 @name SELECT * FROM @name
4
4528
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 relevant fields are Engineer.Name Engineer.Code (where the login in the database is the Engineer.Code)
4
13781
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 three fields, but the problem is that one of its tables varies with the Calendar Year like tblYear2002, tblYear2003, etc. Is there a simple way of doing this? dixie
1
5671
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}'); </script>"; or maybe here, in file2 <?php $tk_req_id = $_GET;
2
5247
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, but I am unable to store a variable for it. Here is a rough copy of what I am making: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
2
3124
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, if not they are redirected to the login page. If logged in they may edit the story. I assign $_GET to $id.
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.