ADO Connection question

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,835
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,

I have a connection between Excel and Access. From Excel, I query Access and use the Recordset method to put the data into a sheet.

Can I use this to somehow Update or Edit an actual query that's in Access ?

Please advise yes or no. I think its No !

Thanks, ABB
 
Best make it a half of shandy for Jon, after last time...
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Jon, that works perfectly too :)

Guess I misinterpreted those Miscrosoft instructions. You guys should be be writing them :biggrin:

One therefore concludes ADO vs DAO is a draw ? :eek:

Thanks again to you both,

Regards, ABB

PS Another question - can Excel get back from Access the query definition ? Then the modify routine
could just use Replace ??
 
Last edited:
Upvote 0
DAO is generally faster and easier so if you are using Access, I'd use DAO.
 
Upvote 0
PS Another question - can Excel get back from Access the query definition ? Then the modify routine
could just use Replace ??

With the ADO one I have been on about, you would just look at the cmd.CommandText. Load it into a string variable if you wish, then do replacements, and then load it back into the CommandText.

One therefore concludes ADO vs DAO is a draw ?
What Rory said. Only because I lack the experience to know any different. :biggrin:
 
Upvote 0
similarly with DAO you can read the querydef's SQL property, run a replace on it and write it back.
 
Upvote 0
Many thanks for last tips -which I'm yet to try as stuck on a really peculiar one.

When I first ran Jon's code using Views collection, it was fine. But the next and subsequent times I'm getting

Run-time error '3265':
Item cannot be found in the collection corresponding to the requested
name or ordinal.

on line

Set cmd = catDB.Views(strQryName).Command

This is the same error as the first version that referenced the Procedures collection. I've spent a hour or two trying to find what's changed or why it worked once and have come up blank.

Any thoughts, Jon ?
 
Upvote 0
I've just created a mock-up and it works for me. I can run it several times and no problems...

Have you made any amendments (other than 'Views') to that sub?
What is going on between calls?
 
Upvote 0
Jon,

It's similar dummy test I've set up here... nothings else is happening and I'm calling this from Excels immediate window.
In Excel -

Code:
Sub DoUC()
Dim tpath$, s$, n$
tpath = GetPath(ThisWorkbook.FullName) & "BackendII.mdb"
s = "SELECT tbl1978.Serial FROM tbl1978;"
n = "Query7"
Call jModifyQuery(tpath, n, s)
End Sub

Sub jModifyQuery(strDBPath As String, _
                strQryName As String, _
                strSQL As String)
   Dim catDB As ADOX.Catalog
   Dim cmd   As ADODB.Command
   
   Set catDB = New ADOX.Catalog
   ' Open the Catalog object.
   catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strDBPath
   
   Set cmd = New ADODB.Command
   ' Get the query from the Views collection.
   Set cmd = catDB.Views(strQryName).Command
   
   ' Update the query's SQL statement.
   cmd.CommandText = strSQL
   
   'Save the updated query.
   Set catDB.Views(strQryName).Command = cmd
   
   Set catDB = Nothing
End Sub

Function GetPath(theName)
GetPath = Left(theName, InStrRev(theName, "\"))
End Function
and in Access Query7's SQL is

SELECT tbl1975.Serial FROM tbl1975;

Really puzzled why it worked once here (and works for you). But it is 2.30am here and may be clearer in the morning. Could resume tomorrow ?

Thanks, ABB
 
Upvote 0
It's the same proc I'm using and I don't get an error. I'm also using mdb. Not sure to be honest.

Is the query still in view if you go directly to the DB?
 
Upvote 0
remember when I said "DAO is generally faster and easier so if you are using Access, I'd use DAO"... ;)
 
Upvote 0

Forum statistics

Threads
1,215,421
Messages
6,124,806
Members
449,191
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top