?
Solved

How do I import two range files from Excel to Access database

Posted on 2014-03-04
17
Medium Priority
?
523 Views
Last Modified: 2014-03-11
I have an excel workbook called mydata.xlsx. The workbook has to tabs (tab "A" and "B"). In each tab I have a name range (name manager) that I want to import into my access database table called tblAmount. The first name range name  is Import1 and the second name range is Import2. How do I import these with code into my table tblAmount?
0
Comment
Question by:Conernesto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
17 Comments
 

Author Comment

by:Conernesto
ID: 39904981
My workbook is located in C:\my documents
0
 

Author Comment

by:Conernesto
ID: 39904985
Above is the path to my workbook
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39905724
Use the DoCmd.TransferSpreadsheet method twice, first with the first range, then with the other range.

Look up the on-line help for the specifics.

/gustav
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:Conernesto
ID: 39906630
I found the following code on line. How would I update below code with my information?

DoCmd.TransferSpreadsheet transfertype:=acImport, SpreadsheetType:=5, _
            tablename:="tmpTableName", FileName:="SomeExcelFile", _
            Hasfieldnames:=False, Range:="WorkSheet!B1:B11"
            'This will import the range B1 through B11
            'The Spreadsheet type = 5 specifies an Excel 5.0/7.0 file
            'format
0
 

Author Comment

by:Conernesto
ID: 39907584
I entered the above code to a command botton (I run this from Forms). I am getting a run time error. Please run the commend button in Menu_frm under forms. What am i doing wrong?
mydata.xlsm
TestImport.accdb
0
 

Author Comment

by:Conernesto
ID: 39907987
I am still trying to get the code to work. I entered the below code. I thing that the problem is after is on the Range portion of the code. I don't know how to include that the tab name to use is "A" and the name range is "Import1:

Private Sub Command4_Click()

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "tblAmount", "C:\My Documents\mydata.xlsm", False, Range = "Import1"

End Sub

conernesto
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39908754
Without the field names you cannot do it this way.
Link the range:

DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel5, "xlsAmount", "C:\My Documents\mydata.xlsm", False, "Import1"

Then use an append query to massage and copy the data from xlsAmount to tblAmount.

/gustav
0
 

Author Comment

by:Conernesto
ID: 39909455
Is there a way to add the field names since I will be importing a lot of excel worksheets?

The three field names that I have are "Number", "Company", and "Amount".

Thank you .

conernesto
0
 

Author Comment

by:Conernesto
ID: 39909476
The range file has the field names that math the fields in the table "tblAmount".
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39909797
Yes, include the field names as the first row in your range, and change parameter Hasfieldnames to True.

Else, as you've seen, the fieldnames expected are F1, F2, F3.

/gustav
0
 

Author Comment

by:Conernesto
ID: 39909827
Can the method be changed from acLink to acImport? How?
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39910772
Yes it the field names match.

/gustav
0
 

Author Comment

by:Conernesto
ID: 39910826
I modified the code as follow but I am still getting a linked excel worksheet vs. importing into my table "tblAmount".

Public Sub Import1_()

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "tblAmount", "C:\My Documents\mydata.xlsm", True, "Import1"
End Sub

conernesto
0
 

Author Comment

by:Conernesto
ID: 39910917
I changed the code to below. When I press the command button , I get an excel link vs. importing the range into my table tblAmount.  



DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel5, "tblAmount", "C:\My Documents\mydata.xlsm", True, "Import1"

conernesto
0
 

Accepted Solution

by:
Conernesto earned 0 total points
ID: 39910949
gustav,

The below code worked.

DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel5, "tblAmount", "C:\My Documents\mydata.xlsm", True, "Import1"

Thank you for all your help!

conernesto
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39911768
Great! You are welcome.

/gustav
0
 

Author Closing Comment

by:Conernesto
ID: 39919995
The information provide by the expert worked. I just wanted to say Thank you.
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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

719 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