473,394 Members | 1,951 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,394 software developers and data experts.

Exporting the results of a listbox to Excel

56
One more question for you! This follows on from this query:

http://www.thescripts.com/forum/thread685289.html

Now I have the search function and everything displays in a listbox correctly, can I get the results of this to export to Excel somehow. Either by opening and populating a spreadsheet or by saving the results to text to be delimted later.

Thanks for any help!
Jul 30 '07 #1
12 11618
JKing
1,206 Expert 1GB
You want everything in the list box to be sent to a text file / excel?
Jul 30 '07 #2
Widge
56
If thats at all possible, yes!
Aug 1 '07 #3
JKing
1,206 Expert 1GB
I don't really do much work with excel. Other than direct imports/exports but here's a little something that I've conjured up. It's fairly simple.

So first off you'll need to make a query and save it. It doesn't matter what's in the query as we're just going to alter it but Access won't allow you to make blank queries and save them. So for this example I've called my saved query qselExport.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim qdef As DAO.QueryDef
  3.  
  4. Set qdef = CurrentDb.OpenQueryDefs("qselExport")
  5.  
  6. 'your code for filling the list box here
  7.  
  8. qdef.SQL = Me.ListBox.RowSource
  9. qdef.Close
  10.  
  11. DoCmd.TransferSpreadsheet acExport, , "qselExport", "testExport"
  12.  
  13. Set qdef = Nothing
  14.  
The logic behind this is we change the SQL of our saved query to match that of the list box's rowsource. Then we just do a simple export of the query. You can be more specific with the filename than "testExport" and add a full path otherwise it will just save to my documents.
Aug 1 '07 #4
Widge
56
I don't really do much work with excel. Other than direct imports/exports but here's a little something that I've conjured up. It's fairly simple.

So first off you'll need to make a query and save it. It doesn't matter what's in the query as we're just going to alter it but Access won't allow you to make blank queries and save them. So for this example I've called my saved query qselExport.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim qdef As DAO.QueryDef
  3.  
  4. Set qdef = CurrentDb.OpenQueryDefs("qselExport")
  5.  
  6. 'your code for filling the list box here
  7.  
  8. qdef.SQL = Me.ListBox.RowSource
  9. qdef.Close
  10.  
  11. DoCmd.TransferSpreadsheet acExport, , "qselExport", "testExport"
  12.  
  13. Set qdef = Nothing
  14.  
The logic behind this is we change the SQL of our saved query to match that of the list box's rowsource. Then we just do a simple export of the query. You can be more specific with the filename than "testExport" and add a full path otherwise it will just save to my documents.
Nice, I'll give it a go this afternoon (must make a coffee first). Cheers!

I just want something simple.

I found a database by someone called Tejpal here:

http://www.rogersaccesslibrary.com/OtherLibraries.asp

but it was WAY more than what I wanted to do.
Aug 1 '07 #5
Widge
56
Extra question, it doesn't recognise QueryDef. Is this a resource I have to import?
Aug 1 '07 #6
JKing
1,206 Expert 1GB
Make sure you have a reference to the Microsoft DAO 3.6 Object Library. To view references open up the VBA editor then click Tools > References and select the reference.
Aug 1 '07 #7
Widge
56
Make sure you have a reference to the Microsoft DAO 3.6 Object Library. To view references open up the VBA editor then click Tools > References and select the reference.
Ah, it was a bit of a typo it seems. It still doesn't like OpenQueryDefs. Its fine with CreateQueryDef which does create a blank query for you, but I can't get it to delete afterwards.

EDIT:

Just tested the export, that works fine! I just need to get the query deleted afterwards. Code so far:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command36_Click()
  3.  
  4.       Dim qdef As DAO.QueryDef
  5.  
  6.       Set qdef = CurrentDb.CreateQueryDef("exportCatalogue")
  7.  
  8.       'your code for filling the list box here
  9.  
  10.       qdef.SQL = Me.List11.RowSource
  11.  
  12.       qdef.Close
  13.  
  14.       DoCmd.TransferSpreadsheet acExport, , "exportCatalogue", Application.CurrentProject.Path & "\testExport"
  15.  
  16.       Set qdef = Nothing
  17. End Sub
  18.  
  19.  
I've tried doing CurrentDb.QueryDefs.Delete ... but I get a bit lost after there.
Aug 1 '07 #8
JKing
1,206 Expert 1GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. Currentdb.QueryDefs.Delete "exportCatalogue"
  2.  
Aug 1 '07 #9
Widge
56
Try this:

Expand|Select|Wrap|Line Numbers
  1. Currentdb.QueryDefs.Delete "exportCatalogue"
  2.  
PERFECT

Thank you v much for being on hand!
Aug 1 '07 #10
JKing
1,206 Expert 1GB
You're welcome.

Jking
Aug 1 '07 #11
Widge
56
Argh, ok, more questions.

What can I do when my export data BREAKS the 65000 row Excel limit?
Aug 1 '07 #12
JKing
1,206 Expert 1GB
Hey, sorry for not getting back to you sooner. I'm really not sure about the constraints of Excel. Again as I said before I really don't use excel all that much at least I haven't yet. My suggestion is to start a new thread asking for a work around for the 65,000 constraint. I'm guessing you'll probably end up having to break things up into separate sheets. This would require more code than I've provided.

Only thing I can think of is to make your queries more specific so you don't hit that many rows.
Aug 3 '07 #13

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

Similar topics

0
by: Hideyuki | last post by:
Hi, I am using asp.net, and I am having a problem exporting datagrid to excel. One column contains numbers such as 123456875468. When this goes to excel, it is displayed as 1.23456E + 11 which I...
3
by: Jeremy | last post by:
Hi, I have a webpage that is taking input from a form and using it as criteria to select data out of an sql database. The page displays an html table with the results. The user can then click a...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
1
by: Suffrinmick | last post by:
Hello Everyone I've built a database using Access 2000 which includes a query which is built using a form containing filters. No problem. When I export the results of the query to excel, (File >...
2
by: Mike P | last post by:
How do you go about exporting data in excel to a C# dataset? Any help would be really appreciated. Cheers, Mike
5
by: Neil | last post by:
Hi I'm currently exporting my datagrid to excel, taking advantage of the fact that excel can render html, the problem is that when i click the button to export it opens in browser, I want the button...
0
by: tomslater2003 | last post by:
Hi! I wanted to know if there is any possibilites to export search results of a particular webpage to excel? I have a website where in search for a specific criteria. After selecting the...
0
by: SupaDaveXP | last post by:
Helllo everyone. I am attempting to export tables from SQL v.8.x to Excel via DTS, but only one row is being created in Excel. Below is the query and the results shown in SQL Analyzer. Only the...
7
by: alf8kitty | last post by:
Hello, Im still very new to php and am having a problem. I return a MySQL query to a form in my php page and I want to be able to export the form data to Excel when the users clicks a link (or a...
1
by: ndedhia1 | last post by:
hello, I am creating a comma delimited text file in php and need to export the results to an excel file. I am creating the text file thru querying a mySql database. Right now, we have the .txt...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.