S
Sky
Access 2007 seems to have buggy behavior with the SQL syntax for an external
file path with brackets. I'm working with Access 2003-compatible .Mdb
databases using Access 2007, if that makes a difference.
To easily reproduce this, here is a simple SQL that uses an external file
path:
SELECT MyField FROM [D:\MyPath\MyData.Mdb].MyTable;
In this example, there is a database named MyData.Mdb in an external path
D:\MyPath, containing a table named MyTable and a field named MyField. You
can easily create a similar query yourself using any front-end database with
any back-end table and path, or even within a single database using any
table and a path to itself.
The above SQL works fine when entered manually into the Access query
designer. It also works in VBA as SQL to open a recordset.
But if you save the query manually, then open it again (or simply create it
in design view and go to SQL view), Access converts the SQL to the
following:
SELECT MyField FROM (D:\MyPath\MyData.Mdb) MyTable;
Notice the brackets have changed to parentheses, and the period separator
has changed to a space. The query still works for the time being, as long as
you make no changes, even though it has a strange SQL syntax that appears to
be an error.
As soon as you make any change to the SQL (such as remove and replace a
character), the query no longer works. You get a message of "Syntax error in
FROM clause". If you use VBA to read the saved QueryDef SQL and try to open
a recordset, you get the same syntax error, because the generated QueryDef
SQL has parentheses. In order to use the SQL, you must convert the "(" back
to "[" and the ") " back to "]." as in the original example.
Manually editing and testing this SQL in the query designer can cause Access
2007 to crash at times. So it seems like a bug. Access 2003 does not do
this.
Even when Access 2007 SQL displays the incorrect parentheses for a saved
query, when I close it and open it in Access 2003 instead, the same query
SQL displays properly with the correct bracket notation. So it appears that
the query is stored properly internally in Jet, but the Access 2007 display
conversion to SQL syntax is incorrect both in the query designer and in the
VBA .SQL property.
For background, I ran into this because I have a complicated multi-table
query, created manually, that uses an external path for comparing
differences with a backup path. Since the backup path can change, I use VBA
to read the SQL and replace the path. However, the stored qdf.SQL causes an
error unless I also convert the erroneous parentheses when using Access 2007
(but not in 2003).
Perhaps this will help someone else who has to work around this problem.
- Steve
file path with brackets. I'm working with Access 2003-compatible .Mdb
databases using Access 2007, if that makes a difference.
To easily reproduce this, here is a simple SQL that uses an external file
path:
SELECT MyField FROM [D:\MyPath\MyData.Mdb].MyTable;
In this example, there is a database named MyData.Mdb in an external path
D:\MyPath, containing a table named MyTable and a field named MyField. You
can easily create a similar query yourself using any front-end database with
any back-end table and path, or even within a single database using any
table and a path to itself.
The above SQL works fine when entered manually into the Access query
designer. It also works in VBA as SQL to open a recordset.
But if you save the query manually, then open it again (or simply create it
in design view and go to SQL view), Access converts the SQL to the
following:
SELECT MyField FROM (D:\MyPath\MyData.Mdb) MyTable;
Notice the brackets have changed to parentheses, and the period separator
has changed to a space. The query still works for the time being, as long as
you make no changes, even though it has a strange SQL syntax that appears to
be an error.
As soon as you make any change to the SQL (such as remove and replace a
character), the query no longer works. You get a message of "Syntax error in
FROM clause". If you use VBA to read the saved QueryDef SQL and try to open
a recordset, you get the same syntax error, because the generated QueryDef
SQL has parentheses. In order to use the SQL, you must convert the "(" back
to "[" and the ") " back to "]." as in the original example.
Manually editing and testing this SQL in the query designer can cause Access
2007 to crash at times. So it seems like a bug. Access 2003 does not do
this.
Even when Access 2007 SQL displays the incorrect parentheses for a saved
query, when I close it and open it in Access 2003 instead, the same query
SQL displays properly with the correct bracket notation. So it appears that
the query is stored properly internally in Jet, but the Access 2007 display
conversion to SQL syntax is incorrect both in the query designer and in the
VBA .SQL property.
For background, I ran into this because I have a complicated multi-table
query, created manually, that uses an external path for comparing
differences with a backup path. Since the backup path can change, I use VBA
to read the SQL and replace the path. However, the stored qdf.SQL causes an
error unless I also convert the erroneous parentheses when using Access 2007
(but not in 2003).
Perhaps this will help someone else who has to work around this problem.
- Steve