473,399 Members | 3,919 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,399 software developers and data experts.

Problem in exporting access table data to an excel file

126 100+
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 2529
PianoMan64
374 Expert 256MB
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
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
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...
1
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...
4
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"...
21
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...
2
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...
7
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...
5
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...
9
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.