Solved

Data Import Script from Excel to Access

Posted on 2011-03-01
13
173 Views
Last Modified: 2012-05-11
Is there a way to build a script in access to import all the pages in a workbook, into separate tables in Access?  For instance, the pages in Excel would be Sales, Inventory, Returns, Demand Forecast.  Then import those pages into their respective tables, tblSales, tblInventory, tblReturns, tblDemand.

How do I do that without running 4 separate import processes?  In actuality, the above example is just a sample of what would have to be completed each week.  We actually have about 25 workbook pages going into Access.

Thank you!  :0)
0
Comment
Question by:pwdells
  • 5
  • 4
  • 4
13 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 35007862
test this codes



Sub ImportAllSheets()
Dim objXL As Object
Dim sTable, sFile As String, xlPath As String, i As Integer
sFile = "Test.xls"
xlPath = "J:\"

Set objXL = CreateObject("Excel.Application")
    objXL.Workbooks.Open xlPath & sFile, , True
    With objXL
        For i = 1 To .workSheets.Count
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
             "tbl" & .workSheets(i).Name, xlPath & sFile, True, .workSheets(i).Name & "!"
        Next
    End With
    objXL.Quit
    Set objXL = Nothing

End Sub

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
ID: 35007877
Can't see what the problem is with using multiple import commands, myself.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35007885
And no disrespect to cap1 but the code he's posted is just 4 import commands wrapped up in other code.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35007933
i know, but if you have 20 woksheets now and 25 worksheets on the next , how are you going to automate this?

going back to your codes and adding or commenting the import line commands?
0
 

Author Comment

by:pwdells
ID: 35008035
The end-users are blocked out of those functions for the application.  The function has to be executed using one step.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35008137
then, try the codes i posted.
0
 

Author Comment

by:pwdells
ID: 35008150
Often there are functions in a process that may come easy to you or me, but not others.  Historically, serious mistakes have been made due to repetition and confusion.  If this automation process works, we may end up importing 50 tables.  This is the only way the client is able to replicate with its customer's sales database, which is locked down considerably.  The only way to import data is via .xlsx files or PDF.  No ODBC is permitted.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35008154
I don't have any argument over your code cap.  It's what I would do.

I was commenting on the requirement...
"How do I do that without running 4 separate import processes?"

Even in a loop each import process is separate from each other import process.

It now appears that the real issue is about using macro actions to do the same thing.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 35008168
or about  NOT using macro actions to do the same thing.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35008182
i really don't like when rules are being changed in the middle of the game.
0
 

Author Comment

by:pwdells
ID: 35008220
What do you mean by "rules are being changed in the middle of the game"???  My request is still the same and currently, I am attempting to implement it within my environment.    :*?
0
 

Author Comment

by:pwdells
ID: 35009110
It worked!  Thank you sooooo much Cap!
0
 

Author Closing Comment

by:pwdells
ID: 35009158
I made a few changes to the variables, but that is always to be expected.  Once I was able to get the script implemented in my environment, it worked without a hitch.  I am so very thankful to Cap for helping me with this task!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question