+ Reply to Thread
Results 1 to 2 of 2

Faster export from excel to access

  1. #1
    Shane Ambry
    Guest

    Faster export from excel to access

    Hi, I am developing a tool to generate forecasts. I use MS Access 97 to store
    the forecast data, but for a variety of reasons I use MS Excel 2000 as the
    user interface.

    My problem is the time it takes to load a forecast. A data set for a
    forecast will have around 5000 - 7000 rows, and I am currently exporting this
    to access on a row by row basis using and VBA to create an SQL statement and
    copying the row to a recordset. An example of the code I use is set out below:

    strSQL = "INSERT INTO [WIP Forecast In] ( Channel, Campaign, Unit, State,
    Version, Period, Type, uKey, Custs, Strategy, FinYr, Manager, AcceptMthd,
    LoadedBy, LoadDate ) "
    strSQL = strSQL & "SELECT """ & ch & """ AS Channel, """ & Camp
    & """ AS Campaign, """ & Unit & """ AS Unit, """ & state & """ AS State, """
    & Vers & """ AS Version, """ & Per & """ AS Per, """ & Typ & """ AS Type, """
    & Key & """ AS uKey, """ & Custs & """ AS Custs, """ & Strat & """ AS
    Strategy, """ & Fyr & """ AS FinYr, """ & mgr & """ AS Manager, """ & AccMthd
    & """ AS AcceptMthd, """ & Usr & """ AS LoadedBy, """ & DatTim & """ AS
    LoadDate;"

    rst.Open strSQL, cnt

    Is there any way that I can load the full set of data in one go? I have
    tried unsuccessfully to create a VBA sub that would copy and then paste
    append the data into the correct table.

    Any help would be greatly appreciated.

  2. #2
    onedaywhen
    Guest

    Re: Faster export from excel to access

    Shane Ambry wrote:
    > My problem is the time it takes to load a forecast. A data set for a
    > forecast will have around 5000 - 7000 rows, and I am currently

    exporting this
    > to access on a row by row basis using and VBA to create an SQL

    statement and
    > copying the row to a recordset. An example of the code I use is set

    out below:
    >
    > strSQL = "INSERT INTO [WIP Forecast In] ( Channel, Campaign, Unit,

    State,
    > Version, Period, Type, uKey, Custs, Strategy, FinYr, Manager,

    AcceptMthd,
    > LoadedBy, LoadDate ) "
    > strSQL = strSQL & "SELECT """ & ch & """ AS Channel, """

    & Camp
    > & """ AS Campaign, """ & Unit & """ AS Unit, """ & state & """ AS

    State, """
    > & Vers & """ AS Version, """ & Per & """ AS Per, """ & Typ & """ AS

    Type, """
    > & Key & """ AS uKey, """ & Custs & """ AS Custs, """ & Strat & """ AS


    > Strategy, """ & Fyr & """ AS FinYr, """ & mgr & """ AS Manager, """ &

    AccMthd
    > & """ AS AcceptMthd, """ & Usr & """ AS LoadedBy, """ & DatTim & """

    AS
    > LoadDate;"
    >
    > rst.Open strSQL, cnt
    >
    > Is there any way that I can load the full set of data in one go?


    Yes, using a ... well, using INSERT INTO..SELECT. Instead of building a
    one row table on the fly in your select clause, as you have done, you
    can SELECT the data from the worksheet and do it all in one hit e.g.
    something like:

    INSERT INTO [WIP Forecast In] ( Channel, Campaign, Unit, State,
    Version, Period, Type, uKey, Custs, Strategy, FinYr, Manager,
    AcceptMthd,
    LoadedBy, LoadDate )
    SELECT Channel, Campaign, Unit, State,
    Version, Period, Type, uKey, Custs, Strategy, FinYr, Manager,
    AcceptMthd,
    LoadedBy, LoadDate FROM [Excel
    8.0;HDR=Yes;Database=C:\MyWorkbook;].[MySheet$];

    The above assumes you have column headers in the workbook that match
    those in the database table.

    Jamie.

    --


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1