That could get decidedly tricky. I suppose if you're sure that the query
includes only one table you could search the SQL for the text ' FROM ' and
then assume that everything between that text and the next space is the name
of the table - unless you have tables with spaces in their names, when
you'll have to search for the "[" and "]" characters following the ' FROM '
text.
Keep in mind that there's nothing preventing anyone from having a field in a
table with the same name as the table itself, or from including the name as
part of a field name, so even after you've found the name of the table, you
can't go blindly replacing it anywhere it happens to appear in the SQL.
This is a decidedly non-trivial parsing operation you've taken on here. I
can't help wondering why it would ever be necessary - if you don't know what
the name of the table is, how do you know it needs to be changed, let alone
to what it should be changed?
I may be going about this in the wrong way.
I have several tables with three fields in them Contract, Amount, Date.
The amounts of each table represent the values of different types of
accounts. I am trying to use a form to allow my users to select which report
they would like to run. A combo box containes each tables name. I only want
to have to use one query. This is why my vba code would need to change the
SQL code within the specified query. Since the user would be running various
reports, the name of the table it is referencing would change each time the
user runs a new report. This is why you would not know the name of the table
that the query is currently using, and would need the vba script to change it
to your desired tablename (the name selected in the forms combobox). The
purpose of this is to essentially create one query which can maneuver to the
users needs rather than creating numerous additional queries for this single
userform.
> That could get decidedly tricky. I suppose if you're sure that the query
> includes only one table you could search the SQL for the text ' FROM ' and
[quoted text clipped - 102 lines]
> >> >> >> >
> >> >> >> > Thank You
tjh - 08 Mar 2005 20:11 GMT
From the code below: My problem is occurring between the FROM and the WHERE
clause.
Any suggestions? Thank you,
qryTest.SQL = "SELECT [Profit Center], [Amount], [Date] FROM ([Forms]![Inv
Rel]![AC1AC]) WHERE (((Date)=[forms]![Inv Rel]![AC1YR]& [forms]![Inv
Rel]![AC1MT]));"
> I may be going about this in the wrong way.
> I have several tables with three fields in them Contract, Amount, Date.
[quoted text clipped - 117 lines]
> > >> >> >> >
> > >> >> >> > Thank You
Brendan Reynolds - 08 Mar 2005 20:16 GMT
The problem is a flawed database design. There should be only one table.

Signature
Brendan Reynolds (MVP)
>I may be going about this in the wrong way.
> I have several tables with three fields in them Contract, Amount, Date.
[quoted text clipped - 144 lines]
>> >> >> >> >
>> >> >> >> > Thank You