Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2005, 09:11 PM
Authorized User
 
Join Date: Jun 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql statement to export data

I have a table containing customer information. I want to give users the option to select the fields they want to export to Excel.

I have an unbound form with check boxes representing the various fields in tblCustomer.

I then bulid a SQL string to make a SELECT statement from the checkboxes checked.

The problem I am having is deciding how to use the SQL SELECT statement how to export the data since TransferSpreadsheet does not use SQL statement.

How should I proceed after making the SQL string?
Thanks for any comments
 
Old January 14th, 2005, 10:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Stoneman,

Pass your SQL string to a routine that:

a. Creates a temporary QueryDef based on your SQL
b. Executes your export using the QueryDef
c. Drops the temporary QueryDef when your done

Sub ExportSQL(strSQL As String)

    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef

    On Error GoTo ExportSQL_Err

    Set db = CurrentDb
    Set qdf = db.CreateQueryDef("qryTemp", strSQL)
    qdf.Close

    DoCmd.TransferSpreadsheet acExport, , "qryTemp", "C:\Test.xls", True

ExportSQL_Exit:
    On Error Resume Next
    DoCmd.DeleteObject acQuery, "qryTemp"
    qdf.Close
    Set qdf = Nothing
    db.QueryDefs.Refresh
    Set db = Nothing
    Exit Sub
ExportSQL_Err:
    Resume ExportSQL_Exit
End Sub

(set reference to the DAO library)

HTH,

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to Sql Server data export mateenmohd SQL Server 2000 4 February 14th, 2006 02:18 PM
How to export SQL Server 2000 data in kwilliams XML 13 November 30th, 2005 10:20 AM
How to export SQL RS data to Excel template johnilett BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 4th, 2005 03:39 AM
Export Data from Excel To Sql Israr Classic ASP Basics 0 January 24th, 2005 02:17 AM
DATA DISAPPEARED!when updating using SQL statement MilkPudding Classic ASP Databases 7 June 24th, 2004 08:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.