473,403 Members | 2,359 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,403 software developers and data experts.

export to excel with criterias



Hi,
I'm using the transferspreadsheet function to export my tables into
excel. Is it possible to export just certain columns? and is it possible
to export it without harding coding the file name and location?

Thanks in advance.
*** Sent via Developersdex http://www.developersdex.com ***
Jan 3 '06 #1
3 1381
On Tue, 03 Jan 2006 05:42:55 GMT, jim Bob wrote:
Hi,
I'm using the transferspreadsheet function to export my tables into
excel. Is it possible to export just certain columns? and is it possible
to export it without harding coding the file name and location?

Thanks in advance.

*** Sent via Developersdex http://www.developersdex.com ***


Create a query with just the fields you wish to export. Export that
query.

You'll have to set the path and file name at some point.
If you want to leave it up to the user, you can use this simplest of
methods.

Dim strWhere as String
strWhere = InputBox("Enter path and file name")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97,
"QueryName", strWhere

The user will be prompted for the path and file name.
Add whatever error handling you need to verify that the path and file
name are properly entered, as well as to exit the sub if the input box
is canceled.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Jan 3 '06 #2
Red
You could always do it progmatically as well....

Here's a little snippet I like to use...

Public Sub MakeXLSReport2()
'Declare your variables
Dim rs As Recordset
Dim XLS As Object, Wkb As Object

'Set up your recordset
Set rs = Currentdb.openrecordset("MyTable")
if rs.recordcount < 1 then goto NoRecords 'It there's no records, let
the user know, and end sub

'Setup your Excel file
Set XLS = CreateObject("Excel.Application")
XLS.Application.Visible = True 'Watch it while it does it's thing
XLS.Application.workbooks.Add 'Make a new workbook
Set Wkb = XLS.Application.activeworkbook.worksheets(1) 'I like to setup
an object for my workbook, makes for less typing
XLS.Application.displayalerts = False 'Turn off alerts while you delet
the extra workbooks (You can skip this and the next 3 lines if you need
all 3 books)
XLS.Application.activeworkbook.worksheets(2).Delet e
XLS.Application.activeworkbook.worksheets(2).Delet e
XLS.Application.displayalerts = True

Wkb.NAME = "My Excel Spreadsheet"

'Now name the columns...
'This is where you can get special... this loop will add ALL the field
names.. you can specify individually if you'd like... of you can name
them yourself...
'i.e. wkb.cells(1,1) = "Name"

X = 1
For Y = 0 To 14
Wkb.cells(X, Y + 1) = rs.Fields(Y).NAME
Next Y
'Now we add all the data... you can do it all at once, or
individually...
'To do it individually, use this:
'wkb.cells(ROW,COLUMN) = rs.("Field Name").value
'NOTE: You CAN leave off the "value" at the end, I just leave it there
for refrence in case Microsoft requires it in later versions

rs.MoveFirst
X = 2
Do Until rs.EOF
For Y = 0 To 14
Wkb.cells(X, Y + 1) = rs.Fields(Y).Value
Next Y
X = X + 1
rs.MoveNext
Loop

GoTo EndMe

NoRecords:
lmsg = "There are no records please try again"
MsgBox lmsg
EndMe:
Set rs = Nothing
set wkb = nothing
set xls = nothing

End Sub

Jan 3 '06 #3
Hi Guys,
thanks for your advice.
Guess I will have to get my user to select the columns they want and
then build a query and THEN export this out.
Cheers.
Jim

*** Sent via Developersdex http://www.developersdex.com ***
Jan 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
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 =...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
5
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
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...
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...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.