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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a query from another database 1

Status
Not open for further replies.

SERT1

Programmer
Sep 13, 2001
33
0
0
CA
Does anyone know how to run a query in another database? I.e. vba code in database1 runs query in database2.
 
Is it an update query or a select query? If select, are you wanting to use it in a report/form or just view it?

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
SERT1,

See if you can make the following work for you:
[tt]
SELECT q0.*
FROM \\MYSERVER\Share\database1.mdb.Query1 AS q0;
[/tt]
hth,
GGleason

 
So far I've had no success in getting these methods to work. Any more suggestions? I'd greatly appreciate it.
 
Lonnie, the answer you gave me worked great!!! Thanks so much. I'll post it below for others to benefit from. The only thing people should keep in mind is that if you are using a front-end, back-end application, this code must be written to the back-end. Here's the code:

Public Function RunOutSideQry()
Dim app As Access.Application

Set app = CreateObject("Access.Application")

app.OpenCurrentDatabase ("c:\test.mdb")

'check to see if the table exist
Dim tbl As TableDef

For Each tbl In app.CurrentDb.TableDefs
If tbl.Name = "MyTable" Then
app.DoCmd.DeleteObject acTable, tbl.Name
Exit For
End If
Next tbl

app.CurrentDb.Execute ("MyQuery")
End Function

Again, thanks sooo much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top