John,
I already have an SQL string in VBA for one table. See below for the code. I
am hoping to find out if and how can I use variables, etc. to select a
different table for the SQL. For example, I can use "dim variablename as
string" and assign a table name to this variable based on the selection from
a combo box. What I am not sure is how to incorporate this variable into the
SQL! When I use "dim" is that a global variable so that I can use it outsite
of a sub? Otherwise, how can I pass it to the SQL? Can I use
"variablename.[First Name] to selec the table? Let me know your feedback
regardless of if I endup combining all the tables into one.
I agree with you about combining the tables into one. There are two issues.
One is each table, even though a contact table, has very different fields.
For example, for one contact type I need to track their spouse
name/phone/email, etc. versus another contact type where I need to track
their assistant's name/phone/email. etc. There are also other differences.
So, it will not be an efficient single table with many empty fields.
Nevertheless I am considering combining them. However, I am hoping that there
is a easy way to combine the tables into one, rather than creating a new one
with all the fields from scratch! Is there a way? Like append or merge one
table to another!
Thanks,
AC Erdal
___ SQL string
SELECT [Last Name] & "," & [First Name] AS Expr1, Sellers.[First Name],
Properties.[Property Address] FROM Properties INNER JOIN (Sellers INNER JOIN
[Transaction] ON Sellers.[ID-Sellers]=Transaction.[ID-Sellers]) ON
(Properties.[ID-Properties]=Transaction.[ID-Properties]) AND
(Properties.[ID-Properties]=Transaction.[ID-Properties]);
________
John W. Vinson said:
I have a query that works fine if I know which table to use for my query.
However, in reality the table I will use is based on the user selection in a
combo box in a form.
So,
If selection is A then use table A
If selection is B then use table B etc.
How do I pass this info to a query? How do I tell query to use A.[First
Name] or B.[First Name]
Thanks,
AC Erdal
To do this you will need to construct the SQL string in VBA code,
incorporating the tablename.
The need to do so, though, VERY strongly suggests that you're making an error
in your database design! Having multiple identically structured tables with
different names is *a very bad idea* and is not normalized. Could you consider
instead incorporating all of these tables into one with an additional field
containing what's now the tablename?