Link to home
Start Free TrialLog in
Avatar of mak345
mak345Flag for United States of America

asked on

Import rounded numbers into Access from Excel

I have a file in Excel 2010 that has fields with numbers rounded to the nearest dollar.  The value has cents in it, but it is just formatted to only show whole dollars.  However, I wish to import the cents into an Access 2010 table as well.  I currently use the following command to import the worksheet:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
         strTable, strFile, True, wks.Name & "$"

For the most part, all of the values are being imported correctly.  However, when there is a column where the top several rows do not have any cents, it seems that when it will not bring in the cents in the subsequent records.  It will bring in the rounded number instead.  I am not 100% sure, but I think there is something in Access where it looks at the top rows to determine the datatype it is importing.  In this case, it seems that it thinks everything will be whole dollars and it ignores the cents.

I know that if someone manually formats the sheet to show 2 decimal places prior to importing, it will work fine.  But, I am trying to eliminate the need for any modification to the original dataset.  What is the best approach at doing this?

Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

With the built-in Transferspreadsheet command, there are not many options.  There are a few approaches:

1. Link to the spreadsheet as a table.   You can then work with it that way.

2. Have the user save the spreadsheet in a CSV format (or other text format).  Then you can use TransferText and specify a import specification that you've written for the import.

3. Same as #2, but link to it as a table and use a schema.ini file to describe the fields.

4. Open Excel as an automation option (Excel needs to be installed where your doing the import), and then loop through the cells and pull the data.  This gives you total control.

Let me know if you need anything more...

Avatar of Kanti Prasad
Kanti Prasad


Is your field in access defined as currency if not try it as currency.
Avatar of mak345


Unfortunately, I can't change to csv, because the spreadsheet is sent over with multiple tabs.  #4 seems to be the best option for me unless I can find somehtng else.  I'd rather not write code to loop through each cell, since there are several thousand rows with 30+ fields.

The field format is standard.  I tried to change it to currency, but that did not work.  It still imported the rounded number.

Your best bet is #1 then.  You'll need to create a link for each sheet in the workbook.  That can be done through the UI, or via code.

Try it manually first and see if you get the results you want.


Will it be possible to ask the source team who gives you the files\outputs to set those columns as 2 decimals?
Avatar of mak345


Creating links is also tough, because the number of links will grow indefinitely, since we are getting multiple files monthly and all have to go into 1 table, which will get messy.

I'm being told the source file will not change.....
<<Creating links is also tough, because the number of links will grow indefinitely, since we are getting multiple files monthly and all have to go into 1 table, which will get messy.>>

 What you do is create a link on the fly.  Once your done with it, delete it.  


 create links that point to a "known" dummy spreadsheet.  As you work with each file, you will delete the existing dummy spreadsheet and copy the one you want to work with to that name.

  All you will need then is one link per possible sheet in a workbook no matter how many files you have.

 As long as you don't try and use the links while the file is not there, you'll get no errors.   I've used this technique a number of times.

Avatar of PatHartman
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial