Need Help In Exporting Access Database Table (1 Viewer)

atfaniqbal

Registered User.
Local time
Today, 02:01
Joined
Jun 22, 2013
Messages
12
I need a code for only exporting rows from my database table with fieldnames and with specific value in a cell column in to excel sheet with date as filename template.... :)
Please somebody can help
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,275
Create a query that selects the columns and rows you want to export. Use the TransferSpreadsheet method to export the query if you want to do this in code. Or, just export the query directly if this is a one-time operation you want to do from the GUI.
 

atfaniqbal

Registered User.
Local time
Today, 02:01
Joined
Jun 22, 2013
Messages
12
I have a button which does TransferSpreadsheet Cmd but it exports all rows and colums with the fieldnames but i want to export only the rows with cell value of "1" in column E.

Please Help Me Build A Query / Code for this, as i am very newbie in access.
Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,275
What is your TransferSpreadsheet using as the "tablename" to export? In Access, tables and querydefs are almost entirely interchangeable so "tablename" should actually be the name of a querydef.

Using the query builder, queries are quite easy to build. Select the table(s) or querdef(s) from the dialog. Close the dialog when you are finished selecting tables and queries. Draw join lines to connect all the tables and queries you added to the grid. Select the columns you want to appear in the output. In the criteria "cell" for column "E" place a 1. run the query to test it. Save it and name it appropriately. Use the query name in the TransferSpreadsheet method
 

atfaniqbal

Registered User.
Local time
Today, 02:01
Joined
Jun 22, 2013
Messages
12
Need Help In Formatting & Layout For The Exported Query Using The DoCmd.TransferSpreadsheet
 

MSAccessRookie

AWF VIP
Local time
Yesterday, 19:01
Joined
May 2, 2008
Messages
3,428
Need Help In Formatting & Layout For The Exported Query Using The DoCmd.TransferSpreadsheet

Simply stated, usng the DoCmd.TransferSpreadsheet method will create a Spreadsheet that resembles the Access Datasheet created when you run the Query. I am not sure what you need to do, but there are other methods available if this is not the Format that you are looking for. More details would be helpful.

-- Rookie
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,275
Just think of me as one of the guys;)

Once you export the data using TransferSpreadsheet, you can open the spreadsheet and add whatever formatting you need. If you don't know how to automate Excel, the easiest way to learn is to open the spreadsheet, turn on the macro recorder and manually format it. Then stop the macro recorder and examine the generated VBA. You can copy this VBA into Access and run it with minor changes.
 

Users who are viewing this thread

Top Bottom