473,326 Members | 2,134 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,326 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 1688
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.