- Local time
- Today, 10:29
- Joined
- Feb 19, 2002
- Messages
- 46,866
But if you use the QBE, you have no need to even look at the generated SQL. So, if you are looking at the SQL, is it because you are then taking the generated SQL and trying to embed it as text?the QBE does have its limitations and annoyances such as excessive use of parentheses and inclusion of superfluous fields.
I'm pretty sure that all the excess parentheses are there to help with converting the string to the graphic view. If you create the string in text view and never save the query after switching to graphic view, ie only save in string view, Access doesn't mess with your string at all. I use this trick for a couple of queries with complex criteria. The problem of course is sometimes I forget so In the databases where I have complex queries which I want to keep as strings (this is mostly because of the way Access seriously messes with the criteria when it is complex rather than the excess parens which are merely annoying), I create a table and paste the raw string into the table. That way I have a backup if I mess up and let Access "help" me.
I'm pretty sure MS wouldn't consider not adding all the parens but now that they are using Monaco, I think they may have added a second storage area so they can save my string separately from their string so even this issue is probably gone.
I don't want to quibble about querydefs vs embedded SQL since it is largely a matter of preference. I was merely pointing out earlier one benefit I had never really thought about and that was documentation. If all your queries are embedded text, there is no easy way to produce a cross reference of what is used where but the task is trivial if you use querydefs since you can use queries to interrogate the MSys tables for the information. I think I've posted excerpts from my documentation tool. If you want the code but can't find it, just ask.
In the past it really made much more of a difference which choice you made but the the stats came down to querydefs were better for two reasons.
Generating an execution plan takes time and space. When you use the QBE, Access generates the execution plan the first time you run the query and saves it with the querydef. Therefore all future executions use the saved querydef. So technically the execution is faster. In reality, unless you are running the same query hundreds of times, you wouldn't ever feel slowness so this is unlikely to ever cause a real problem in most applications. However the second issue was space and this one has been cleared up so you no longer need to worry about it. Access isn't good at garbage collection. For most things, you actually have to run a C&R to get Access to discard all of its scratch pad area which it used to create the execution plan. So, this accumulated over time and caused huge bloating issues if you didn't regularly C&R.
So, technically, today the QBE is still more efficient due to the pre-compile, but the difference isn't enough to worry about in the vast majority of apps so VBA vs QBE is really a matter of preference unless you want documentation. In that case QBE wins again

Last edited: