Question

Equivalent to QueryDef in ADP

Asked by: marc_butler

Hi,

I'm currently starting to look at migrating our database to an Access Data Project (adp) from it's current form as an mdb but one of the first stumbling blocks I've come across is that the following code doesn't work in the adp.

Set qd = CurrentDb.QueryDefs("FLTransportInstructions")
qd.sql = sql & " WHERE (([CLAIM.Ref])=" & Ref & ");"
qd.Close

I use it to get the sql statement from an existing query and then alter it to filter for the one reference, mainly when producing letters or reports but at the moment it's just dropping out on the first line.

I've recreated my query in my adp project using a view but I need a way to get the sql statement from the view so I can add the ref and then use the ALTER VIEW syntax.

Any help or better ideas to this problem would be appreciated.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-16 at 08:43:28ID24736693
Tags

QueryDef

,

ADP

,

Access VBA

Topics

Access Coding/Macros

,

Microsoft ADP

,

SQL Query Syntax

Participating Experts
5
Points
500
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. To ADP or not to ADP
    I am in the process of moving several systems (stock control, accounting, and others) to an SQL server backend. Currently these systems use either a C-ISAM based file access method or an Access database. My two options are Delphi or staying with Access. I am more comfortable ...
  2. Accessing Querydefs in adp
    Hi, I want to change the sql that is 'exported' to excel from access I want code something like: dim qd as dao.querydef set qd = currentdb.querydefs("AllChecks") qd.SQL = "SELECT * FROM myTable where myColumn =" & me.txtCol.value DoCmd.OutputTo acOut...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jimpenPosted on 2009-09-16 at 16:47:39ID: 25351530

I believe the issue is that the CurrentDB and QueryDef and such all reside under the DAO regime, which is unique to the Access/JET.

You'll have to convert it to the ADO version and do something along the lines of
------------------------------------------------------
SQL = "CREATE VIEW FLTransportInstructions " & _
          "AS " & _
          "SELECT * FROM CLAIM WHERE (([CLAIM.Ref])=" & Ref & ");"

executeSQL (SQL, CONNStr)
------------------------------------------------------

I'm not up on my ADO so I'll ping some other experts to give you some guidance.

 

by: vadimrapp1Posted on 2009-09-16 at 18:08:22ID: 25352000

With adp, the queries reside on server side, and often you don't need them at all. Create sql statement in code by concatenation, then execute it.

sql = "select * from my claim inner join transportations on claim.transport_id = transportations.id where claim.ref = " ref
instructions = currentproject.connection.execute (sql)(0)


It should be noted however that Access works best if you let it do data manipulations by itself, i.e. if you bind forms etc. to sql statements, and let Access run those queries when it wants - rather than run them in code.

 

by: jimpenPosted on 2009-09-16 at 18:46:55ID: 25352186

I'm guessing that he is doing it to export/attach data to an external destination. I commonly do a query on the fly to attach to an e-mail and then delete it right after.

 

by: LPurvisPosted on 2009-09-16 at 20:42:11ID: 25352656

Just to offer that I'd agree that the manipulation of existing server objects (even when improved upon by switching to creation of temporary server objects - other than actual Temporary objects) is non-ideal for the reasons already stated. You're not operating on local objects anymore - which offers a great deal of convenience, flexability and concurrency.

If you want to describe the process that you're actually performing in all this it will help provide an appropriate overall solution.

I do want to just raise a flag over the earlier "Access works best if you let it do data manipulations by itself".
In that "best" is, of course, a subjective term. :-)
If you feel that Access exists primarily for developing fast (almost prototype only) applications then the binding everything philosphy gives great results. But an application will often involve much more than that - for example running statements in code or performing other operations other than through the UI. (And of course from a performance perspective - allowing full control to have handled through bound forms can be less than the optimal arrangement).

A bound form in an ADP operates with a slightly different mentality anyway.  

FWIW I agree that bound forms are probably Access greatest strength (subforms going hand in hand with that).
I personally use them a vast majority of the time - naturally. :-)

Cheers.

 

by: aikimarkPosted on 2009-09-17 at 00:25:27ID: 25353506

when you open a form or report with DoCmd, you can supply a filter criterion as one of the [optional] parameters.

 

by: vadimrapp1Posted on 2009-09-17 at 05:03:24ID: 25355048

LPurvis, it's not quite subjective; it's based on years of answering the questions, each beginning with totally unnecessary code that opens separate connection, creates ado command, carefully fills all parameters, then runs the command and finally assigns the recordset to be the recordsource of the form. Certainly, in serious application you will have numerous direct data manipulations, but there's big difference between the philosophy "bind what you can, use ado with the rest" and "ado everything, then bind what you need on the form".  Many novices in ADP often don't even know that that difference exists, they immediately step on the 2nd path and begin producing pages of code.

The result of the 1st approach is, naturally, much shorter code, or even no code at all, hence much shorter development cycle and better manageability of the code. Why coding manually what the tool already does? besides, until Access 2003, touching me.recordset resulted in guaranteed crash several manipulations later.

As for the performance - could you give an example where you achieve better performance by un-binding?

 

by: JDettmanPosted on 2009-09-17 at 05:53:28ID: 25355476

marc,

Your question aside, I would seriously look at not using an ADP type setup. Instead I would use the old tried and true technique of using a robust backend (ie. SQL Server) and then use linked tables via ODBC to access the data

Why? As of 2007, the ADP feature has been dropped from Access, so your going to be stuck using A2000 or A2003. Neither of those is being updated to work with newer versions of SQL Server. For example, A2003 doesn't play well with SQL Server 2005 up. You end up updating the server side objects in SQL.

Second item is that most of your app will work unchanged. This is a big benefit in my mind as you can move to a robust backend relatively painlessly and move into more of a true client/server setup as time permits (use of pass through queries, stored procedures, etc). Third, it opens the door to using other backends besides SQL Server. With an ADP, you stuck with SQL Server like it or not. Fourth, you can use DAO or ADO (or even mixed).

Note however that by simply using ODBC you *might* see a performance decrease. Most don't, but moving to a client/server type setup does need a bit of a mind shift both in app design and development.

You might find that you need to move a few critical tasks to a pass through query or stored procedure right off. Also true client/server apps typically don't do things like bind a table directly to a form, where in the Access/JET world that is almost always done an even encouraged.

There are many apps that work quite well just with simple ODBC connections. It's easy enough to try and I would do so before continuing with the ADP route.

FWIW,

JimD.

 

by: LPurvisPosted on 2009-09-17 at 06:35:12ID: 25355895

vadimrapp1, it's hard for me to express just how much I don't want to get into this...
But to at least address some of your points so I've not just ignored them - I'm not fundamentally disagreeing (nor was I in my previous post).
ADP's offer great functionality for implicit use of SQL Server objects. But, for example, I find Input Parameters a little limiting even thought they're great in concept.

I wasn't advocating ADO everything, bind the rest. Just pointing out that there are alternative viewpoints. (I've answered a question or two myself over the years - so I'd still maintain that it's subjective, based on each experts preference).

That Access 2003 was the final stable version we'd been waiting for regarding form recordset operations isn't in dispute. That it's the version to use for that reason and others is pretty much widely accepted still (we'll see just how good 2010 is when it gets pushed and proded properly).

Performance? Really only the old story with Access of implicit commitals. You can bunch up operations into a single hit on the server rather than as a user navigates if it's of benefit.
That and the inevitable refreshing that Access will perform when it deems it required.
(By the way, I'd be talking about truly unbound Vs bound here. Assigning a recordset to a form is still a bound form - merely late bound).

To mention Jim's point about availability of ADPs, they weren't dropped from 2007, they were made more difficult to create though.
They are still fully supported - not depricated at all - but no functionality additions were made. (The same is true for Access 2010 - they're still there).
MS does indeed advocate ACCDB with linked tables now. And there's nothing really wrong with that (especially if you know what you're doing) but we don't listen and follow MS' lead implicitly do we? ;-)

The ability to work with data designers from Access to the SQL Server does indeed require that the version of SQL Server is equal or older than the Access release. (They don't "play nice" in that respect :-). However the data access and operations are unaffected by versions in that way.

I'd agree you'll find the transition a lot simpler by moving to ODBC links rather than the ADO oriented ADP.
(And it's my considered opinion that familiarity with ADO is essentially a pre-requisit for working with ADPs in all but the simplest of applications).

Cheers all!

 

by: JDettmanPosted on 2009-09-17 at 07:09:35ID: 25356377

<<To mention Jim's point about availability of ADPs, they weren't dropped from 2007, they were made more difficult to create though.
They are still fully supported - not depricated at all - but no functionality additions were made. (The same is true for Access 2010 - they're still there).>>

 Wow.. wasn't aware of that.  Everything I had heard/read up to the release of A2007 said that ADP's were being dropped and not to expect any changes required for future releases of SQL Server.  In fact I know someone who works with the Microsoft team directly and this is the line he's always stated.  I've never heard him say otherwise.

   Just goes to show you that I've never used A2007<g> and no one has ever corrected me on that either up to this point (which I'm very surprised at as I've stated that numerous times).  Very sorry for the mis-information.

<<MS does indeed advocate ACCDB with linked tables now. And there's nothing really wrong with that (especially if you know what you're doing) but we don't listen and follow MS' lead implicitly do we? ;-)>>

 yes, if you look in the MSDN article on migration issues for A2000/A2003, Microsoft does not recommend using ADP's, but using a MDB/ACE with linked tables.

Here's the article:

http://technet.microsoft.com/en-us/library/cc178973.aspx

 it's about half way down.

Leigh,

  I was under the impression though that no changes have been made in the ADP functionaility.  So does A2007 play nice with SQL Server 2005, but not 2008?

JimD.

 

by: LPurvisPosted on 2009-09-17 at 07:19:26ID: 25356514

Hi Jim.

>> So does A2007 play nice with SQL Server 2005, but not 2008?
Yes that's right. (Continuing the definition of "play nice" to mean able to read and work in the data designer - data operations and connections are still unaffected by versions).
To be honest (not that I use ADPs much at all for live work) I've never minded that designer issue. I prefer to work on designing with SQL Server objects using its own tools - i.e. Management Studio (even though it runs like a bit of a dog on my old laptop).

MS making the designers work with a version of SQL Server doesn't seem to count per se as changes in functionality - merely fixing/updating existing functionality.

I've not been a fan of 2007 myself (vocally so and in forums).
For me it offered too little (for developers) with too many new issues. But it wasn't the complete picture and the world should be seeing better from 2010.

Cheers.

 

by: vadimrapp1Posted on 2009-09-17 at 07:28:08ID: 25356637

Here's good comment: link

Here's directly from Microsoft:

"They (ADP) will continue to run in 2008 with support for design against SQL 2008--that said, we did very few new features that were specific to ADPs. ADPs continue to be the best option for a class of applications but development efforts likely will continue to focus in areas  where the vast majority of our customers use--mdb/accdb."

 

by: vadimrapp1Posted on 2009-09-17 at 07:28:36ID: 25356647

"in 2008" - he obviously meant "in 2010".

 

by: LPurvisPosted on 2009-09-17 at 07:44:44ID: 25356842

I don't see that quote in the link when I follow it.
Perhaps it's just the wrong link.
Sylvain is a very knowledgable chap with expertise in several disciplines including Access - but he doesn't speak for MS. ;-)

 

by: vadimrapp1Posted on 2009-09-17 at 08:01:50ID: 25357014

That quote is not from Sylvain's post, it's from Microsoft.

 

by: LPurvisPosted on 2009-09-17 at 08:12:55ID: 25357098

I see - they're separate.
Any idea where that MS quote is from then? I've been reluctant to speak too much on that subject but a public quote from MS would alleviate such limitations for me.

 

by: vadimrapp1Posted on 2009-09-17 at 11:28:18ID: 25359332

> Any idea where that MS quote is from then?

sorry, can't disclose. They are going to make a post to this effect on Access blog (http://blogs.msdn.com/access ). Please don't quote it outside of this thread.

If their future blog post also mentions "vast majority of our customers using mdb/accdb", it will be fun to discuss.

 

by: aikimarkPosted on 2009-09-17 at 11:48:55ID: 25359558

It could be an even simpler solution...
1. if you look at querydef SQL, it is semicolon terminated.
2. The posted code does not remove the semicolon before appending the WHERE clause.  If it didn't cause an error, it would surely cause the query parser to ignore everything after the semicolon.
3. Assuming the best case, the snippet should correct this problem.

================
As I already posted, the ability to add selection/filter criteria to the form and report open operations is the best way to operate.

It is NOT a good design to change querydefs in this manner for this purpose.
 

Set qd = CurrentDb.QueryDefs("FLTransportInstructions")
strSQL = qd.SQL
strSQL = Left$(strSQL, InStrRev(strSQL, ";")-1)
qd.sql = strSQL & " WHERE (([CLAIM.Ref])=" & Ref & ");" 
qd.Close
                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: jimpenPosted on 2009-09-17 at 15:26:48ID: 25361663

WOW! And the asker hasn't even posted back yet!

I'm thinking that when the "official" blog post shows up, several of you should collaborate to talk about ADP vs Acc ## & ODBC as an article.

 

by: vadimrapp1Posted on 2009-09-17 at 15:44:47ID: 25361799

since I will be certainly watching for this, those who are interested can send me email to vadimrapp at sbcglobal dot net, so we will then coordinate the assault.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...