Ask Experts Questions for FREE Help !
Ask
    santoshdream's Avatar
    santoshdream Posts: 11, Reputation: 1
    New Member
     
    #1

    Jan 31, 2009, 06:35 PM
    Export access table to Excel format
    Hi,

    I am trying following code its working fine.

    Private Sub Command3_Click()
    '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
    'Change Based on your needs, or use
    'as parameters to the sub
    strExcelFile = "C:\D\DATA.xls"
    strWorksheet = "WorkSheet1"
    strDB = "C:\D\PS.mdb"

    ''' strTable = "Test"

    strTable = "SELECT DATA.Account, DATA.Affiliate, DATA.Deal, DATA.MFR, "
    strTable = strTable & " DATA.GL, DATA.YTD_Balance, DATA.Adjustment, "
    strTable = strTable & " DATA.Difference, DATA.Description, DATA.[Owned By] "
    strTable = strTable & " FROM Data WHERE (((Data.[Owned By]) Like "
    strTable = strTable & """SDTR-MAN - FX""))ORDER BY DATA.Difference"


    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 Sub


    But my proble is that I want to use the following query code in my above mentioned code but its showing error while I'm going to click submit button.

    SELECT DATA.Account, DATA.Affiliate, DATA.Deal, DATA.MFR, DATA.GL, DATA.YTD_Balance, DATA.Adjustment, DATA.Difference, DATA.Description, DATA.[Owned By]
    FROM DATA
    WHERE (((DATA.Difference) Not Like "0") AND ((DATA.[Owned By]) Like "SDTR-MAN - FX" Or (DATA.[Owned By])="SDTR - FX" Or (DATA.[Owned By])="SDTR"))
    ORDER BY DATA.[Owned By];

    Please help me.



    Please find the enclosed file for your reference. I want to put this code in the FORM1 to " Export EXCEL BUTTON "

    I need same help in HOW TO IMPORT EXCEL DATA IN ACCESS TABLE (please see my form1)

    " I WANT TO IMPORT DATA FROM MY EXCEL SHEET "DPS.XLS"



    " Thanks a lot for your time and consideration "

    Regards
    Attached Files
  1. File Type: zip macro.zip (46.9 KB, 51 views)
  2. ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    Feb 1, 2009, 08:11 AM

    Ok, Try this SQL

    SELECT DATA.Account, DATA.Affiliate, DATA.MFR, DATA.GL, DATA.YTD_Balance, DATA.Adjustment, DATA.Difference, DATA.Description, DATA.[Owned By]
    FROM DATA
    WHERE (((DATA.Difference)<>0)) OR (((DATA.[Owned By]) In ("SDTR-MAN - FX","SDTR - FX","SDTR")));

    However, you might find it easier to use the TRANSFERSPREADSHEET method rahter than Office Automation.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Using one Excel list table in multiple worksheets [ 2 Answers ]

I have a workbook containing 13 worksheets. Sheet 13 contains two list tables. I need to link sheets 1 through 12 to the list tables in sheet 13 so that only one set of lists has to be updated when changes occur. Please help me...

Format Cells in Excel 2007 [ 4 Answers ]

Is there a way in Excel to automate adding hyphens in a specific position in a column of numbers (like a mac address list) For example: 0021e96c4183 00-21-e9-6c-41-83 HOWEVER When I use this method Home tab, Cell group, click on Format On Number tab from the Format Cells dialog screen I'd...

Excel - frequency / mode / pivot table. [ 0 Answers ]

Hi there, I'm struggling to achieve my end goal in Excel; I have a list of dates (presently the list of dates is divided into individual worksheets with 20 rows and 5 columns of dates per worksheet. I have 30-40 worksheets). My objective is to obtain a list of the dates that match...

How to export database of chart prepared in powerpoint to excel worksheet [ 1 Answers ]

I have prepared one chart in powerpoint using excel worksheet. The worksheet was updated in powerpoint and no of slides of powerpoint were prepared. Now I want to import these charts in excel worksheet. I need help to perform this function.

Excel Format [ 7 Answers ]

I need someone help. Everyday I need to format data like the following 1003, 1876, 1952, 2011, 2048, 2057, 2073, 2094, 2111, 2128 This gets pasted into one cell in a spreadsheet. I would like to be able to format it so it goes into the sheet 1003 1876 1952 etc into separate cells. Is this...


View more questions Search