Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have been a grateful member of this site for several years. I love this site and refer everyone to it!..."

Geography

Where in the world do Tek-Tips members come from?
FancyPrairie (Programmer)
9 Aug 12 9:27
From my current db, I open a form that exists in my library database (codedb). Upon pressing a button on the form, my code creates a query and saves it in my current db. I then want to open that query via DoCmd.OpenQuery "QueryName", acViewNormal. However, because the form and/or code is being executed within my library database (codedb or CodeProject), the DoCmd.OpenQuery is looking for the query in my library database rather than my current database.

What would be the syntax to force DoCmd.OpenQuery to run in my current database?

Here's a brief example of my code:

CODE

Dim dbs as DAO.Database
Dim qdf as DAO.QueryDef

Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef("TempQuery", "Select...")

DoCmd.OpenQuery "TempQuery", acViewNormal 

I have tried:
CurrentProject.Application.DoCmd.OpenQuery "TempQuery", acViewNormal
AND
Dim app as New Access.Application
Set app = GetObject(CurrentProject.FullName)
app.DoCmd.OpenQuery "TempQuery", acViewNormal
FancyPrairie (Programmer)
9 Aug 12 9:52
I found a solution. Since DoCmd.OpenQuery first looks in the library database for the query and then in the current database, I use a different query name if my current database is my library database.

For example, if my current database is abc.accdb, then I name the query "TempQuery". If I'm running the library database directly (that is, the library database is my current database) then I name the query "TempQuery_Lib". Consequently, I have eliminated my problem.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close