473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Export Select Qry to Excel

23
I'm using Access/Excel 03. I've created a query that opens fine, but when I use docmd.transferspreadsheet I receive ERROR 3011. Jet can't find the query qryMyQuery.

Expand|Select|Wrap|Line Numbers
  1.  Set db = CurrentDb
  2. Set qdf = db.QueryDefs("qryMyQuery")
  3. qdf.SQL = strSQL
  4. qdf.Close
  5. DoCmd.OpenQuery "qryMyQuery"
  6.  
  7.  
  8. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryMyQuery", "C:\Documents and Settings\Name\Desktop\test.xls"
  9. Set db = Nothing
  10. Set qdf = Nothing
Can anybody tell me what I need to do so that it recognizes the query? Thanks!
Sep 18 '08 #1
3 3079
ADezii
8,834 Expert 8TB
Try:
  1. Explicitly Declare your Database Object Variable.
    Expand|Select|Wrap|Line Numbers
    1. Dim db As DAO.Database
  2. Explicitly Declare your QueryDef Object Variable.
    Expand|Select|Wrap|Line Numbers
    1. Dim qdf As DAO.QueryDef
  3. Declare a String Variable to hold the SQL Statement.
    Expand|Select|Wrap|Line Numbers
    1. Dim strSQL As String
  4. Assign a SQL Statement to strSQL prior to setting the SQL Property of the QueryDef Object.
    Expand|Select|Wrap|Line Numbers
    1. strSQL = "Select * From Employees"
    2.  
    3. qdf.SQL = strSQL
  5. In toto, not the dog in the Wizard of Oz!
    Expand|Select|Wrap|Line Numbers
    1. Dim db As DAO.Database
    2. Dim qdf As DAO.QueryDef
    3. Dim strSQL As String
    4.  
    5. Set db = CurrentDb
    6. Set qdf = db.QueryDefs("qryEmployees")
    7.  
    8. strSQL = "Select * From Employees"
    9.  
    10. qdf.SQL = strSQL
    11. qdf.Close
    12.  
    13. DoCmd.OpenQuery "qryEmployees"
    14. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryEmployees", "C:\ADezii\testamundo11.xls"
    15.  
    16. Set db = Nothing
    17. Set qdf = Nothing
    18.  
  6. Any further questions, feel free to ask.
Sep 18 '08 #2
J360
23
Thanks, works great now. I just had to move the position of my set db and set qdf.
Sep 19 '08 #3
ADezii
8,834 Expert 8TB
Thanks, works great now. I just had to move the position of my set db and set qdf.
Glad it worked out for you.
Sep 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: atse | last post by:
Hi experts, I retrieve data from the database and display on ASP, then I export these data to a file, like Excel (the best) or text file. Is it possible? I think it is possible, but how can I do...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
4
by: Anthony Cuttitta Jr. | last post by:
I'm working on some procedures where Access queries are exported to Excel, and then later on, those same workbooks are openned, and I need to target a specific original sheet. Sometimes there will...
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
3
by: stronghold888 | last post by:
Hello everyone, I created a database in Access and on my form, I inserted a button that exports data into a ready Excel template. The export works fine, but I have one problem and it's from my...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
0
by: sandervanee | last post by:
Hello, I am trying to export several Access 2003 select queries to Excel 2003 using an Access macro. I'm using the macro command "TransferSpreadsheet" to export the queries. This going quit well,...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.