Problem in exporting access table data to an excel file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JFKJr
    New Member
    • Jul 2008
    • 126

    Problem in exporting access table data to an excel file

    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.

    Code:
    Function ExportTableToExcel()
    'Export function
    'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL
    'REFERENCE TO DAO IS REQUIRED
    
    Dim strExcelFile As String
    Dim strWorksheet As String
    Dim strDB As String
    Dim strTable As String
    Dim objDB As Database
    
    strExcelFile = "C:\ExtractPolicyList.xls"
    strWorksheet = "WorkSheet1"
    strDB = "C:\Example1.mdb"
    strTable = "ImportedData"
    
    Set objDB = OpenDatabase(strDB)
    
    'If excel file already exists, you can delete it here
    If Dir(strExcelFile) <> "" Then Kill strExcelFile
    
    objDB.Execute _
    "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
    objDB.Close
    Set objDB = Nothing
    End Function
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2
    You want to check from:
    Code:
    objDB.Execute _
    "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    ".[" & strWorksheet & "] FROM " & "[" & strTable & "]"
    TO:

    Code:
    objDB.Execute _
    "SELECT [b]<<Name the fields that you want to select>> [/b]INTO [Excel 8.0;DATABASE=" & strExcelFile & _
    ".[" & 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.

    Comment

    Working...