Solved

Export access 2010 form records to Excel

Posted on 2013-12-23
3
1,852 Views
Last Modified: 2013-12-26
Does anyone have a way to export to excel only those records displayed on a filtered form in Access 2010 top Excel 2010?

Sandra
0
Comment
Question by:ssmith94015
3 Comments
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 200 total points
ID: 39736836
Hi,

pls try by creating a temporary table

Dim qrydef as QueryDef
DoCmd.DeleteObject acQuery, "qryTmp"
Set qrydef = CurrentDb.CreateQueryDef("qryTmp", Me.myForm.Form.RecordSource)
DoCmd.OutputTo acOutputQuery, "qryTmp", acFormatXLS, "C:\myXLFile.xls", True

Open in new window

Regards
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 300 total points
ID: 39736842
first create a query "qryExport"  with sql statement

select * from NameOfTable

use this code in the click event of a  button

Private Sub cmdExportToExcel_Click()
Dim sWhere As String, qd As DAO.QueryDef, nSql As String
If Me.Filter = "" Then
    sWhere = ""
    Else
    sWhere = Me.Filter
End If

Set qd = CurrentDb.QueryDefs("qryExport")
qd.sql = "select * from NameOfTable"
nSql = qd.sql & " Where " & sWhere
If Len(sWhere) > 0 Then
qd.sql = nSql
End If

DoCmd.TransferSpreadsheet acExport, 10, "qryExport", _
        "C:\ExportedToExcel.xlsx", True,


end sub
0
 

Author Closing Comment

by:ssmith94015
ID: 39740355
They both worked at setting up the query and I needed the transfer methodology
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now