My query runs in DAO but not in ADO

I guess I can write one function that will handle all these situations.
 
jal,

There is a simpler solution. Instead of storing the SQL statement in a Query, then using syntax like the following:
Code:
cmd.CommandText = qDef.SQL

...you can simply hard code the SQL statement into your program, like the following example:
Code:
cmd.CommandText = "SELECT T1.*" _
    " FROM (SELECT MyField1, MyField2 FROM MyTable) AS T1"
 
jal,

There is a simpler solution. Instead of storing the SQL statement in a Query, then using syntax like the following:
Code:
cmd.CommandText = qDef.SQL

...you can simply hard code the SQL statement into your program, like the following example:
Code:
cmd.CommandText = "SELECT T1.*" _
    " FROM (SELECT MyField1, MyField2 FROM MyTable) AS T1"
I often do it that way but it takes extra time, and reduces readability which makes debugging harder. And often I introduce bugs when translating to the above syntax.

I am guessing virtually no one creates a long query that way. We usually start with "normal SQL", test it in SQL view, and then translate to VBA only if needed.

As I said, what I'd really like is for Access to leave my query the heck alone. The adjusted and/or compiled versions should be kept hidden, viewable only at my request.

Another beef is that I find it pretty ridiculous that even Access 2003 doesn't allow embedding comments into the SQL. This too would greatly increase readability.

Nonetheless Access is fantastic software. So who am I to complain?
 
I am guessing virtually no one creates a long query that way. We usually start with "normal SQL", test it in SQL view, and then translate to VBA only if needed.

On the contrary, more programmers than you think choose manually creating the SQL statement over using the query builder, particularly for more complex queries, and hard-coding them into the VBA program. This is not to say that they do not ever use the Query builder as a starting point, but I would like to point out that embedding the SQL statements in code provides a facility for better securing the queries when compiling your application into an MDE file (Queries can be exploited far more easily than compiled code).
 

Users who are viewing this thread

Back
Top Bottom