Results 1 to 2 of 2

Thread: transferspreadsheet outside of Access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    transferspreadsheet outside of Access

    Hi,

    I have gotten this to work if inside Access, but I need it to work from an executable outside. The code I have keeps trying to open the database, I don't think it should or need to..
    Basically, I need to import Excel (multiple sheets per file, each sheet updates a different table) into the database.
    What am I doing wrong,
    Thanks


    Private Sub cmdGO_Click()

    Dim objAccess As Object 'New Access
    Dim objExcel As Object 'New Excel

    Set objAccess = CreateObject("Access.Application")
    objAccess.OpenCurrentDatabase "C:\temp\Test_Wetlands\Test_Wetlands.mdb"

    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = True

    strExcelFileName = "C:\temp\Test_Wetlands\ImportData.xls"

    '== must import specifically the Excel Sheet to the table
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Evaluated_Wetland", strExcelFileName, True, "Sheet1!"
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Evaluated_Wetland_Unit", strExcelFileName, True, "Sheet2!"


    Set objAccess = Nothing
    Set objExcel = Nothing


    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: transferspreadsheet outside of Access

    You probably aren't doing anything wrong.

    However, it can't import something unless it is open to receive the import. The fact that it keeps trying to open the database makes perfect sense.

    Could you import your hand into a glove that was sewn shut?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width