tablename as parameter

A

Aivars

Hello,
Is it possible to use a parameter instead of table name such as:

select field1, filed2.... from [Parameter Name] where...
I have identical queries except each one is based on different tables
I tried but Access is saying that it cannot find the table (parameter
name).
Using Access 2007


Aivars
 
G

Graham R Seach

Aivars,

You can build a SQL statement in VBA, then execute it or create/modify a
QueryDef for later use.

strTableName = "Table1"
strCriteria = "field1 = 123"
strSQL = "SELECT field1, field2 FROM " & strTableName & " WHERE " &
strCriteria

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Aivars said:
Hello,
Is it possible to use a parameter instead of table name such as:

select field1, filed2.... from [Parameter Name] where...
I have identical queries except each one is based on different tables
I tried but Access is saying that it cannot find the table (parameter
name).
Using Access 2007


Aivars

--


Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
A

Aivars

Thanks Graham,
Will give it a try today

Aivars
Aivars,

You can build a SQL statement in VBA, then execute it or create/modify a
QueryDef for later use.

strTableName = "Table1"
strCriteria = "field1 = 123"
strSQL = "SELECT field1, field2 FROM " & strTableName & " WHERE " &
strCriteria

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Aivars said:
Hello,
Is it possible to use a parameter instead of table name such as:

select field1, filed2.... from [Parameter Name] where...
I have identical queries except each one is based on different tables
I tried but Access is saying that it cannot find the table (parameter
name).
Using Access 2007


Aivars

--


Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
J

John W. Vinson/MVP

Aivars said:
Hello,
Is it possible to use a parameter instead of table name such as:

select field1, filed2.... from [Parameter Name] where...
I have identical queries except each one is based on different tables
I tried but Access is saying that it cannot find the table (parameter
name).

Let me suggest that you "unask" the question...

Having multiple identically-structured tables differing only by table name
is almost certainly *incorrect* design. Data should be stored in tables -
not in table names! You should really consider having all these tables
concatenated into one table, with another field containing what's now the
table name.

John W. Vinson [MVP]
 
A

Aivars

Dear John,
I really appreciate your advice and I have learned a lot from your
posts in newsgroups since i have started doing things in Access. I
more and more understand the proper design and normalization issues.
As I mentioned in my particular case I am doing consolidated financial
annual accounts for a mother and a daughter companies.
There are two completely independent accounting databases involved -
each database are kept separately for each company. The two databases
are kept on a remote Interbase server and have separate client part
written in Borland Delphi and all the financial accounting is done via
the client interface.
The companies operate as separate units, they have different
customers, businesses, they also have separate base currencies, in
short they are separate
What I am doing - I need to consolidate the accounts. I have linked
the main tables in Interbase database needed for making the trial
balances via ODBC in an Access 2007 file and doing the consolidation
procedures and calculations in Access.
It results for example I have two similar structure tables - similar
fields, field types, etc., and to calculate the trial balance the
query is the same except the name of the source tables.
Thats why I thought that to have the table name as a parameter would
be good idea.

Thanks
Aivars



Aivars said:
Hello,
Is it possible to use a parameter instead of table name such as:

select field1, filed2.... from [Parameter Name] where...
I have identical queries except each one is based on different tables
I tried but Access is saying that it cannot find the table (parameter
name).

Let me suggest that you "unask" the question...

Having multiple identically-structured tables differing only by table name
is almost certainly *incorrect* design. Data should be stored in tables -
not in table names! You should really consider having all these tables
concatenated into one table, with another field containing what's now the
table name.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top