Solved

How to apply an action query to a second database.

Posted on 2014-11-19
7
99 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 49

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

15 Experts available now in Live!

Get 1:1 Help Now