Solved

Using Queries with a Linked Database

Posted on 2013-01-10
5
179 Views
Last Modified: 2013-01-22
I'm building an application that manages a large amount if imported data and is used by a number of users. I have split the tables out from the rest of the application in the usual way, with the "Back End" parked up on the server.

Unfortunately, at the request of the user group, I can't embed the various queries in the code - as is my usual practice. Instead, the query names are stored in a table and executed in a sequence managed within that table.

Equally unfortunate, however, is that this methodology requires all of the queries to reside in the BACK END .accdb. In addition, any Make Table queries that are executed break the links to the back end tables and replace them with the new tables in the client .accdb.

Both of these are a royal pain in the neck!

Is there a way around this, assuming that use of the "DoCmd.OpenQuery strQueryName" method is something I am stuck with?

Thanks.
0
Comment
Question by:Buck_Beasom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38762616
Try this revision to your back-end queries:

SELECT YourField
INTO YourTable IN "C:\YourPath\YourTargetDBName.mdb"
FROM YourTable
'etc

Open in new window


You can use an IN clause to specify a given database.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38763015
You might want to take a look at my article on Creating and Using Temporary Tables.

Additionally, you indicate that " this methodology requires all of the queries to reside in the BACK END .accdb"; this is not true. Although the Table containing the query names resides in the BE, the code (and queries) are still processed in the FE; the queries must reside in the Front End.

Also, if you are running ACTION queries (Make table, Append, Delete, Update) then you should not be using DoCmd.OpenQuery, you should be using the Execute method, like:

db.Execute strSQL, dbFailOnError

OR

db.QueryDefs("QueryName").Execute dbFailOnError
0
 

Author Comment

by:Buck_Beasom
ID: 38774164
Fyed.

Thanks. Your comments helped, but before closing the question I would like some more input on the alternative query execution methods you provided. Why are these better for Action queries than DoCmd?

Thanks.
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 38774233
Because the Execute method (which is available for both the database and querydefs) has an optional Options argument associated with it.  One of those options is 'dbFailOnError', which will raise an error if your query fails to execute (which is not the case with the RunSQL method).

Theoretically, if you check for the values in your fields, make sure they are the right data types, ... you should not have any errors when you run an Action query, but you NEVER know what a user might enter in a textbox, and the ability to trap for errors is the major advantage of using the Execute method.

HTH
Dale
0
 

Author Closing Comment

by:Buck_Beasom
ID: 38806782
Thanks. I did notice that if I am executing a query that joins a query and a table, the query for the embedded SQL must be in the back end .accdb, but that is the only case.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question