473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trying to import Excel into Access, but no records are being moved

Seth Schrock
2,965 Expert 2GB
I'm using the following code to import data from Excel to Access:
Expand|Select|Wrap|Line Numbers
  1. Public Sub ImportMatrix()
  2. Dim db As DAO.Database
  3. On Error GoTo Error_Handler
  4.  
  5. Set db = CurrentDb
  6.  
  7. DoCmd.Hourglass True
  8.  
  9. db.TableDefs.Refresh
  10. DoCmd.TransferSpreadsheet _
  11.     TransferType:=acImport, _
  12.     SpreadsheetType:=acSpreadsheetTypeExcel9, _
  13.     TableName:="tblMatrix", _
  14.     FileName:="\\ftcbank1\docs\sschrock\My Documents\Database Stuff\FTC Morgage Rate Database\Mortgage Matrix.xls", _
  15.     HasFieldNames:=False, _
  16.     Range:="MatrixTable"
  17. db.TableDefs.Refresh
  18.  
  19.  
  20. Exit_Procedure:
  21.     Set db = Nothing
  22.     DoCmd.Hourglass False
  23.  
  24.     Exit Sub
  25.  
  26. Error_Handler:
  27.     'Call ErrorMessage(Err.Number, Err.Description, "modImport: ImportMatrix")
  28.     'TSCs_ReportUnexpectedError "ImportMatrix", "modImport", "Custom info"
  29.     Resume Exit_Procedure
  30.     Resume
  31.  
  32.  
  33. End Sub
  34.  
I have a named range within the excel file titled MatrixTable and from looking on the MSDN website, I should be able to use the name of the range. I don't get any errors, but no data gets transferred. tblMatrix is a pre-existing table. I'm not sure what to try at this point.
May 10 '13 #1
5 1887
TheSmileyCoder
2,322 Expert Mod 2GB
I have used the following bit of code without incident:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tbl_CustomCommentImportReplies", strImportFile, , "Comments!A:L"
This works to import columns A through L on the sheet named Comments.

I remember that I often spend a fair amount of time tinkering with Excel exports to get them to work just as I want. Have you tried adding a exclamation before Matrixtable, so that:
Expand|Select|Wrap|Line Numbers
  1. Range:="!MatrixTable"
I am really just guessing here.
May 10 '13 #2
neelsfer
547 512MB
I have had so many issues using TheSmileyCoder code here above, because my field types (ie text or number etc) were different in Excel and Access for the same fields. If they are the same, then it should import in no time.
May 11 '13 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Most excel sheets I issue for use as remove data entry, I lock down before issue, so that users can only type in certain fields, and do certain actions. This greatly limits the number of things that can go wrong, although it is not always an option.

I also usually import to a temp table first, to weed out any import errors before appending to the live data.

Are you sure the import range is typed correctly? What happens if you deliberately type a non-existing importrange such as DonaldDuck? Does it give an error message then?
May 11 '13 #4
Seth Schrock
2,965 Expert 2GB
I tried moving it to my computer so that there is no network problems and I put in the actual range so I now have
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblMatrix", _
  2.             "C:\Databases\Mortgage Matrix.xlsm", False, "NewSheet!A1:E126"
I still get no error message (I did try DonaldDuck as the range and didn't get an error message that time either), but still, no records are imported. I made sure that all of the data types in the excel file are numbers and that they match the access table.
May 13 '13 #5
Seth Schrock
2,965 Expert 2GB
I figured it out. Very dumb mistake. I had my table missing a field that was in the excel sheet. I ended up having the excel sheet have field names and I was able to use the named range just like I had in my OP. Thanks Smiley for your help.
May 13 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bburton | last post by:
I'm using a form in Access which was used as a bug tracker. The users could update the record with an attachment. (The data type of the field that is used for attachments is the OLE Object) I...
1
by: Reggae | last post by:
Hello, I am looking for the most efficient way to programmatically batch import excel files into MS Access. The excel files are not lined up in a row and currently I am going to each file so I...
2
by: john | last post by:
I have 400 different Excel-spreadsheetfiles, same structure, all with only one record in it, and all residing in the same folder. Every now and then new Excel files are being added. In my Access...
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
7
nehashri
by: nehashri | last post by:
hello i have my data stored in different Ms Excell sheets. now I am planning to make a database of the data i have. but i m confused whether to use Postgresql or mySQL for the same. i had plans to...
2
by: Dave Williams | last post by:
Im not a techie but run a small business in UK. We take instructions from clients from emails hard copy, spreadsheets etc and put them on excel templates then import to Access. A client wants us to...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
1
by: jollyroger | last post by:
I have searched the web forums, and can't seem to find an answer to this particular problem I have. In an excel sheet, cells in one column have formatted text in the "wrapped" cells. For many of...
4
by: dowlingm815 | last post by:
I am importing an Excel 97-2003 file into Access 2003. The number of rows within the Excel file is 101,9992. When completed the Access import, only 65,535 are import. Is Access limited, if so,...
0
by: prashantdixit | last post by:
Hi, I have beent trying importing Excel data with one column containing PDF/JPEG file name to access 2007. I have a Excel file with few columns One of the columns named as "Reference". The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.