Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble executing DoCmd.OpenQuery via vba code

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have created an access database that contains my library of routines (Lib.accdb). I then reference this library in my other databases (Other.accdb).

Via code in Other.accdb, I open a form that exists in my library database (Lib.accdb). On the library form is a button. Via the onclick event I issue the command Set qdf = dbs.CreateQueryDef("TempQuery", strSQL). Following this line of code I issue the command DoCmd.OpenQuery "TempQuery", acViewNormal.

I get an error indicating that it can not find "TempQuery". I'm assuming that the "CreateQueryDef" is creating the query in my library db (Lib.accdb) while the DoCmd.OpenQuery is attempting to open the query in Other.accdb. Or visa versa. The reason I believe this must be the case is because if I open my library database and then open the form and press the button, DoCmd.OpenQuery works.

Is there a way to create the query and open it all within the same database?
 
What is the definition of the dbs variable that you run your Set qdf line against?

John
 
Howdy FancyPrairie . . .

Instead of [blue]Set dbs = CurrentDB[/blue]
Try . . . . . [green]Set dbs = CodeDB[/green]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 

[blue]?[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top