473,804 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in exporting access table data to an excel file

126 New Member
Hi! I have exported an access table data into an excel file using the following code. However, the code exported all the data to the excel sheet starting from 'A' cell (first column). But I want to export all the data into the excel starting from cell B (second column) and include the heading "Extract Policy" followed by checkboxes in 'A' cell.

Can anyone suggest me how to do this? Thanks a million in advance.

Expand|Select|Wrap|Line Numbers
  1. Function ExportTableToExcel()
  2. 'Export function
  3. 'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
  4. 'REFERENCE TO DAO IS REQUIRED
  5.  
  6. Dim strExcelFile As String
  7. Dim strWorksheet As String
  8. Dim strDB As String
  9. Dim strTable As String
  10. Dim objDB As Database
  11.  
  12. strExcelFile = "C:\ExtractPolicyList.xls"
  13. strWorksheet = "WorkSheet1"
  14. strDB = "C:\Example1.mdb"
  15. strTable = "ImportedData"
  16.  
  17. Set objDB = OpenDatabase(strDB)
  18.  
  19. 'If excel file already exists, you can delete it here
  20. If Dir(strExcelFile) <> "" Then Kill strExcelFile
  21.  
  22. objDB.Execute _
  23. "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
  24. "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
  25. objDB.Close
  26. Set objDB = Nothing
  27. End Function
Jul 16 '08 #1
1 2555
PianoMan64
374 Recognized Expert Contributor
You want to check from:
Expand|Select|Wrap|Line Numbers
  1. objDB.Execute _
  2. "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
  3. ".[" & strWorksheet & "] FROM " & "[" & strTable & "]"
TO:

Expand|Select|Wrap|Line Numbers
  1. objDB.Execute _
  2. "SELECT <<Name the fields that you want to select>> INTO [Excel 8.0;DATABASE=" & strExcelFile & _
  3. ".[" & strWorkSheet & "] FROM [" & strTable & "]"
Replace <<Name the fields that you want to select>> with the actual names of the fields that you want to export separating each field name with a comma ","

example

select Name, address, Phone From TableName

Hope that helps,

Joe P.
Jul 17 '08 #2

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

Similar topics

3
8015
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
3
9250
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
1
10528
by: Alex | last post by:
Hi all, I've seen this noted in many posts, but nothing I've checked out gives me any clue on how to do this. Basically as my topic says, I have a DTS and I simply need to export some data from a table in MS SQL 2000 to an Excel spreadsheet. I also need to automate this process so it can run nightly and each new day a new spreadsheet will be on a network share for us to pick-up.
4
3951
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear" TEXT field that contains data such as 2000/01, 2001/02, etc. If I export a Query with this kind of data to Excel, it gives me the text value of this field; however, when I export a Report bound to this TEXT field, Excel gives me the values 36526,...
21
6251
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the code use multiple excel tabs within a workbook???? Anyone have vba code that would create a temp table write 65,000 records to it, export those to excel, clean the temp table, append the next 65,000 records, export it to excel with a different...
2
3188
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
7
5773
by: semijoyful | last post by:
OS: Win XP SP2 Access version: 2003 Excel version: 2003 I am new at this, as I am sure you have gathered from this post title:) I am working on a form where users can input data in Access and at the end of the day be able to press a button on the form that would update that data to a single exel spreadsheet. The following is the code for the module. When I click on the button in the form, It takes me to VBS Debugger. I then type...
5
2137
by: Dave | last post by:
Hello, I have a possible problem exporting a text field that happens to contain dates (but is not a date field) when using TransferText in MS Access 2000. I am exporting a query to a text file using TransferText in a module. One of my fields is a text field called "invoice description". This field may include any content including dates (e.g., 01/01/2006, 1/1/2006, 01/01/06, Invoice #1, Jan 2006, 293842, etc. are all
9
2784
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no data at all that it came from my query named "HVACWindwardQuery" and there's an error on it...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.