I wrote a lot of queries in Access, however, when I imported the queries into Excel, I only found maybe 10-20% of my queries.
Here is a copy of my Access DB:
http://www.2mbit.com/~tesl
David
Main Topics
Browse All TopicsIs it possible to do a query from Access to Excel OR getting Excel to query Access DB? If so, I would appreciate some step-by-step instructions - I'm well versed in Excel, but a newbie in Access.
I need to run several queries from a specific Excel spreadsheet to an Access DB that I have in place.
The Access DB is what used to be an Excel spreadsheet, where I moved all the data info there.
Thanks in advance!
David
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I wrote a lot of queries in Access, however, when I imported the queries into Excel, I only found maybe 10-20% of my queries.
Here is a copy of my Access DB:
http://www.2mbit.com/~tesl
David
David,
Use MS Query (C:\Program Files\Microsoft Office\Office10\MSQRY32.EX
Save it as YourQuery.dqy
When you import to Excel.. look in "My Data Sources" and select YourQuery.dqy
I experienced the same missing queries when importing directly to Excel.. but all were available with MSQuery..
Bud
Weird.
When I put this in MSQuery this sample from my Access SQL Query:
SELECT IIf(AvgInfluentBOD!Expr1<>
it responded with the following errors:
SQL Query can't be represented graphically. Continue Anyway? (I said OK)
Could not add table 'AvgInfluentBOD'
What do I need to do?
It sounds like you have multiple OUTER JOINS in your query..
Microsoft has published details on what causes the error as well as some workaround solutions..
http://support.microsoft.c
Bud
This is not an outer join.
According to Access Query, my AvgInfluentBOD is this:
SELECT Avg([300I (Influent)]![BOD Lab mg/l]) AS Expr1, Format(Date,"yyyy-mm") AS Expr2
FROM [300I (Influent)]
WHERE ((([300I (Influent)].Date) Between [Start Date] And [End Date]))
GROUP BY Format(Date,"yyyy-mm");
And AvgInfluent looks like this:
SELECT Avg([Flow Data Calculations]![Influent Calc]), Format(Date,"yyyy-mm")
FROM [Flow Data Calculations]
WHERE Date Between [Start Date] And [End Date]
GROUP BY Format(Date,"yyyy-mm");
hawkeyex,
I've been looking at your DB. The following worked fine for me (Office 2003):
In Excel, use menu Data/Import External Data/New Database Query...; select the Access DB and choose your query. I've chosen one by random and it worked fine. It appears as I've seen all your queries in the menu, I haven't checked thoroughly though.
Do not use MS Query for complex queries. It's too simplistic for this. Build the queries in MS Access and and use them directly (i.e., use MS Query to get the results directly as they are in the MS Access created query).
Hab
You can pass SQL statements directly to Access (or any other ODBC datasource) using ADO.
In Excel, open the VB Editor (Alt+F11), add a reference to Microsoft ActiveX Data Objects 2.x
...then use code like this to run your statements.
Sub Test()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OL
strSQL = "SELECT * FROM MyTable"
Set rs = con.Execute(strSQL)
'your recordset now contains the results of the SQL query...
'you can use that however you want such as to populate as range of cells.
con.Close
Set con = Nothing
Set rs = Nothing
End Sub
WATYF
Hi WATYF, long time no see....
There is a good example of WATYFS suggestion at http://www.erlandsendata.n
As per the previous post it requires that you send a reference to Microsoft ActiveX Data Objects 2.x
Cheers
Dave
Hey Dave... gotta stop in every once in a while to keep in "good graces" with my EE account. :o)
Sorry for cutting that previous post short... I was comin' down with something earlier today at work... barely made it home. :oP Anyway... here's a full example of how to use this.
As mentioned, add a reference to ADO 2.x and then use something like this:
Sub Test()
'Declare variables
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Integer
'Open connection to the database. Change the DB path and username/password (if necessary)
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OL
'Place your SQL statement here
strSQL = "SELECT * FROM MyTable"
'Populate the recordset
Set rs = con.Execute(strSQL)
'Here's where you have some options. The simplest thing to do is just dump the contents of the rs into the worksheet.
'This will dump it all into sheet 1 in the workbook, starting at cell A1.
Sheets(1).Cells(1, 1).CopyFromRecordset rs
'You could also loop through the recordset and just pull out certain records or columns.
'This isn't a practical necessity, because you could always just specify the fields you want to pull in your SQL query
'But just so you understand the flexibility of the object....
'This will pull just the first, third, and sixth column from the rs
'and populate the first three columns in the first sheet of your workbook.
i = 1
Do While Not rs.EOF
Sheets(1).Range("A" & i).Value = rs.Fields(0).Value
Sheets(1).Range("B" & i).Value = rs.Fields(2).Value
Sheets(1).Range("C" & i).Value = rs.Fields(5).Value
i = i + 1
Loop
'You can also call the fields by name instead of index number...
'such as: Sheets(1).Range("A" & i).Value = rs.Fields("Field1").Value
con.Close
Set con = Nothing
Set rs = Nothing
End Sub
If you're looking for speed.... Index your tables in Access on the key fields that you'll be pulling from/summing on/using in your WHERE clause. Also, the combination of ADO and Access is the fastest I've found so far for multi-purpose data extraction on-the-fly (into Excel)... I've done benchmarks with pretty much every way there is to pull data into Excel (ADO, ODBC, DDE links, separate application instances, MS Query, linked Pivot Tables (et al).. pulling from Access, Excel, raw text files, SQL Server, etc. etc. etc.) This method will get you your data... it will get it fast... and you will have a flexible/scalable architecture to work with should you decide to change/enhance whatever it is you're trying to do later on.
Plus, you can make this process part of a user-defined function in Excel, so you can pull data from an Access DB straight into a cell by calling a function (just like using SUM or AVERAGE or whatever). It's handy as hell for what I do... YMMV.
WATYF
Business Accounts
Answer for Membership
by: BTogniettiPosted on 2004-09-13 at 09:35:59ID: 12045657
David,
If the Access side is complete.. all you need to do is import it to Excel.. do this by following these steps;
Toolbar > Data > Import External Data >
Navigate To & Select Your DB >
Select Table or Query > OK
This will place your data in a new worksheet.. this data can be refreshed manually by right-clicking on your data sheet and "Refresh Data" or automatically updated by right-clicking and selecting "Table Options - Refresh On Open OR Refresh Every ?? Seconds/Minutes/Etc.