Solved

How to apply an action query to a second database.

Posted on 2014-11-19
7
97 Views
Last Modified: 2015-02-02
I have opened a second database which I can update with code.  (.addnew .update, etc.) but how can I do it with a query?

Thanks in advance.
0
Comment
Question by:CRB1609
  • 4
  • 2
7 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 40454365
Hi,

I suppose you have an ADO connection

then pls try

.Execute

Sub test()

Dim objCommand As ADODB.Command
Set objCommand = New ADODB.Command

With objCommand
.ActiveConnection = ADOConn
.CommandText = "UPDATE Clients " & _
"set ClientName = 'John' " & _
"Where ClientID = 10"
.Execute
End With

End Sub

Open in new window


Regards
0
 

Author Comment

by:CRB1609
ID: 40454455
Thanks, but I should been more clear.  I want to create the query in Query Design and apply the completed query by name.    I was hoping to do something like this:

  Dim dbe As PrivDBEngine, wrk As Workspace, db1 As Database, db2 As Database
   Dim, OutputFilePath As String

   OutputFilePath = "C:\Celebrant Assist V3\CelaRept.accdb"
   Set dbe = New PrivDBEngine
   Set wrk = dbe.Workspaces(0)
   Set db2 = wrk.OpenDatabase(OutputFilePath, False, False)

  '  Run a named querythat updates a table in db2
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 40454521
You can continue:

Dim qdy As QueryDef

Set qdy = db2.CreateQueryDef("NameOfQuery")
qdy.SQL = strSQL ' Your action SQL code.
qdy.Execute

If you like, you can create a temp query this way:

Set qdy = db2.CreateQueryDef("")

/gustav
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:CRB1609
ID: 40463247
It looks like I can't do what I want to do but points for the effort.
0
 

Author Comment

by:CRB1609
ID: 40463265
I give up.  I wanted to award the points to the nexperts but now it seems I can't.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40463270
?

> I have opened a second database which I can update with code.  ..but how can I do it with a query?

I showed you exactly that.

/gustav
0
 

Author Closing Comment

by:CRB1609
ID: 40585617
Thanks for trying.  Sorry I didn't close the question, earlier.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now