Button to Run a query in another database

  • Thread starter Thread starter The Boondock Saint
  • Start date Start date
T

The Boondock Saint

Is there a way I can set up a button in one database that allows me to run a
query which is set up in another database....

For example.. a button in database 1 which runs a delete query which is in
database 2

Cheers
 
The Boondock Saint said:
Is there a way I can set up a button in one database that allows me
to run a query which is set up in another database....

For example.. a button in database 1 which runs a delete query which
is in database 2

Is this button supposed to delete records in database 2? If so, then
you could open a DAO Database object on that database and use that to
execute the query:

Dim dbOther As DAO.Database
Dim strDBPath As String

strDBPath = "C:\Your Path\YourDB.mdb"

Set dbOther = DBEngine.OpenDatabase(strDBPath)

dbOther.Execute "YourDeleteQuery", dbFailOnError

dbOther.Close

Set dbOther = Nothing
 
Thanks Dirk... Ive put in the data... but im getting a error saying

"User Defined Type not defined"

any ideas?
 
The Boondock Saint said:
Thanks Dirk... Ive put in the data... but im getting a error saying

"User Defined Type not defined"

any ideas?

I guess you're using Access 2000 or 2002, which don't automatically add
a reference to the DAO object library. While in the VB Editor
environment, click Tools -> References, locate "Microsoft DAO 3.6 Object
Library" in the list, and put a check mark in the box next to it. Then
compile your project and see if the problem is gone.
 
Oh i should point out that im using Access 2000
The Boondock Saint said:
Thanks Dirk... Ive put in the data... but im getting a error saying

"User Defined Type not defined"

any ideas?
 
Brillant :) that fixed it up a treat :)

Its a delete query which works... but for testing I had it as just a normal
display query.... can it not do these?
 
Hi Boondock,

The .execute method is reserved for action queries only. These are queries
that do not include a recordset. Perhaps the easiest way to run a remote
select query is to create a new query in your database. Dismiss the Show
Table dialog without selecting any tables. Click on View > SQL View in query
design. Enter the following SQL statement:

SELECT * FROM [Your Query Name] IN "C:\Your Path\YourDB.mdb";

Give the new query a name, such as qryRemote. If you want to run this query
from code, use something like this:

Sub test()
On Error GoTo ProcError

DoCmd.OpenQuery "qryRemote"

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure test..."
Resume ExitProc

End Sub


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Brillant :) that fixed it up a treat :)

Its a delete query which works... but for testing I had it as just a normal
display query.... can it not do these?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top