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

Use a variable in place of a table Name in Select statement

2
My Access 2003 application imports periodical Excel spreadsheets, which are in the same format, into sequential Tables.
I wish to to use the same query each period to process the latest Table using;

Dim strTablename as String
strTablename = [latest Table name]

Select * from strTablename

The Query produced returns strTablename as the name of the 'linked' Table

What am I doing wrong??
Feb 12 '08 #1
3 2344
ADezii
8,834 Expert 8TB
My Access 2003 application imports periodical Excel spreadsheets, which are in the same format, into sequential Tables.
I wish to to use the same query each period to process the latest Table using;

Dim strTablename as String
strTablename = [latest Table name]

Select * from strTablename

The Query produced returns strTablename as the name of the 'linked' Table

What am I doing wrong??
The correct Method for using a Variable Name in place of a Table Name within a SELECT Statement is:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2. Dim strSQL As String, strTableName As String
  3.  
  4.  
  5. strTableName = "Employees"
  6. strSQL = "Select * From " & strTableName
  7.  
  8. Set MyDB = CurrentDb()
  9. Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  10.  
  11. MyRS.MoveLast: MyRS.MoveFirst
  12.  
  13. Debug.Print "The number of Records in " & strTableName & " is: " & MyRS.RecordCount
  14.  
  15. MyRS.Close
  16. Set MyRS = Nothing
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. The number of Records in Employees is: 11
Feb 13 '08 #2
BarryS
2
adezii

The addition of the Variable after the '&' fixed the problem

Many thanks
Feb 13 '08 #3
ADezii
8,834 Expert 8TB
adezii

The addition of the Variable after the '&' fixed the problem

Many thanks
You are quite welcome.
Feb 13 '08 #4

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

Similar topics

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 =...
3
by: Tim | last post by:
Hi All, I have a small issue that I can't seem to figure out. I have a SQL statement that is dependant on the results of a drop down to chose which table to select from. Unfortunately it does not...
3
by: r rk | last post by:
I am trying to write a utility/query to get a report from a table. Below is the some values in the table: table name: dba_daily_resource_usage_v1...
4
by: Murph | last post by:
Hi, I'm new to ASP.NET and have a problem which i'm hoping will be easy to answer... i have only used VB, HTML and Flash up until now! I am designing an ASP page which uses OleDb to retrieve...
14
by: Matt | last post by:
I need to add the following variable into an SQL statement and not sure how to do it. strGCID needs to be inserted into the following statement: SQL = "SELECT tblContacts.* FROM tblContacts...
5
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve...
8
by: tnspc | last post by:
I'm trying to access a Request.Form variable and plug it into an SQL statement, so that the statement will select just the particular data I need. Here's the offending snippet of code: sql =...
2
by: Kevin | last post by:
I am having difficulty updating a variable page-time-stamp in the following snippit. The variable time-stamp is initialized from the attribute time-stamp from the log element. Some of the page...
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
3
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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.