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

Export query result (datasheet) on command button to ms excel

Dear friends,

I am using A2010. I am trying to export my filtered datasheet to excel. Tried TransferSpreadsheet() but nothing helped.

Lastly I tried below code but excel only displays 1 column.

Expand|Select|Wrap|Line Numbers
  1.   Dim strOriginalRecordSource As String
  2.     Dim strNewRecordSource As String
  3.  
  4.     strOriginalRecordSource = Me.RecordSource
  5.     strNewRecordSource = "SELECT * FROM Tasks WHERE ([EmployeeId] =" & Me.cboEmployee & ")"
  6.  
  7.     Me.RecordSource = strNewRecordSource
  8.  
  9.     DoCmd.OutputTo acOutputForm, Searchbyempid, , , True
  10.  
  11.     Me.RecordSource = strOriginalRecordSource
  12.  
  13.     DoCmd.OutputTo acOutputForm, Searchbyempid, , , True
  14.  
Also, please check the below code which i used earlier,

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel3, "Tasks", Employee.xlsx, True
Thanks in advance .

Looking forward for a solution :)
May 26 '15 #1
4 1692
Also, in excel the instead of field name in A1 Column, Combobox name is displayed. But the values under it are correct
May 26 '15 #2
Well, I done it myself.

But their is a problem in it.

It displays data for the first time. but it displays the previous searched data even though the option in combobox is changed.

The result is been reflected in the datasheet but not in excel. So I need to close the form and reopen it if I want to change the data.

Please find the below code and suggest if something is inappropriate.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputForm, "Tasks SubForm", acFormatXLS, "Tbl1XLS.xls", True
  2.  
Actually the main problem was, I filtered the subform based on VBA code on after update event.

Expand|Select|Wrap|Line Numbers
  1.     Dim Myemp As String
  2.     Myemp = "select * from Tasks where ([EmployeeId] =" & Me.cboEmployee & ")"
  3.     Me.Tasks_subform.Form.RecordSource = Myemp
  4.     Me.Tasks_subform.Requery
  5.  
Any help is appreciated :)
May 26 '15 #3
This is for the first time my query is not resolved on this forum. I feel helpless. Its a simple question though. If I am not clear to my points please ask any types of questions, I will try my best to answer them, as I really need to resolve it.

Thanks in advance.
May 27 '15 #4
NeoPa
32,556 Expert Mod 16PB
@Sandy.

Most people will look at the thread and see three responses, so no need to look further.

Your question is full of changes and extra details. The rules are one question per thread as that is most helpful to everybody - especially you, the questioner. Only someone with a lot of time to spare will look at this because it will take them a long time to read all that you've posted and longer to make real sense out of it.

You need to do the work of formulating the question FIRST. Make it as simple as you can. Don't expect the readers to have to do the work to make it make sense.

If you must add comments later, which means you haven't considered the question fully beforehand but will happen often because doing it fully is actually very hard, then add the comment into the first post as an edit. If you keep adding new posts then it will look like a busy thread and we'll all assume you already have someone helping you.
May 28 '15 #5

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

Similar topics

3
by: azzi2000 | last post by:
This should be rather simple. I have a query using different link tables and 2 parameters. The query works perfect. However I need to export or save the result in an Access table in order to...
1
by: ALaurie10 | last post by:
I keep getting the "in use by another user or process" error. Is there some way to lock the table temporary. I want a user to click a command button on a form that runs a Macro that opens a...
3
by: AccessHunter | last post by:
Hi, I need to automate a process that would export a query to a text file, tab delimited. I know how to do it manually. Is there a way to automate the same? Please treat this as urgent. ...
2
by: jatin32 | last post by:
Hi, I have to export query result to EXCEL file in certain location. how do I do that? I have used DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, , , , , acExportQualityScreen
5
xxoulmate
by: xxoulmate | last post by:
i wanted to export the query result into csv file is there any way to do it., e.g. select field1,field2 from table into csvfile
1
by: titli | last post by:
Hi Friends, I have some code in an already built application. Now the output pivots in .xls files is not matching with input data. The output .xls has summarized results whereas , the input...
5
by: Jinzuku | last post by:
Hi, I'm trying to map an export function to a command button to my Access form (called Results). However, I would like it so that the "Save As" window appears when I try to export the table so...
2
by: Jennytranxxx | last post by:
How do I assign a delete query onto a command button? I have read a few forums and it has told me to: Go to Properties Rename the Name and Caption, so i've renamed it to Runquery Under Event -...
3
by: moonrb | last post by:
Hi How Can I View Datasheeet On Form When Using "Select Query" By A Command Button. I am using access 2002 Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.