Hello green,
Even though your field types may be the same, there is something about the
Excel data Access does not like. I am very familiar with this as I have to
import serveral Excel files each month. Here are some things you need to
consider:
1. Look at the validation rules and data rules in your Access table. The
easiest way to handle this is to be sure there is no Input Mask, no
Validation Rule, set Required to No, set Allow Zero Length to Yes. In other
words, allow anything to come in. We will deal with bad data later.
2. Null Values. This can be your biggest problem. If you have an Excel
column that has numbers in it, but is formatted as General, any cells where a
user did not put a value in will come into Access as Null. This will cause
an error on import. It will usually be imported, but it will cause any
calculations used on that cell to be incorrect. If you can control this
problem, the best thing to do is be sure that any such columns are formatted
as some kind of number. Then, and empty cell will come into Access as zero.
3.Once you have it in, then clean it up. I use a table that is only for
importing. It is not related to anything. In fact, I have found that if you
put import tables in the Front End database instead of the Back End,
performance is better. I then have an append query that validates the data
and puts it into the production table in the Back End database. One trick
here, to avoid the Nasty Null problem is in my Append Query, every numeric
field has the Nz function in the Update To row of the query: Say the field
is dblMyNumber, In the Update To row I put:
= Nz([dblMyNumber],0) This converts any nulls to zero, but allows any
other value.
As to automation. Even though I do not user Macros, If you are not a VBA
programmer, they can be very useful. You need to create a Maco to do all
this for you. To get your Excel sheet in, create a new Macro, here are the
settings to import your Excel sheet:
First, Turn warning messages off (This is option, but it saves having to
answer a bunch of warnings.
Action - SetWarnings
Warnings On - No
Next, Delete old data from the import table:
Action - RunSQL
SQL Statement - DELETE * FROM MyImportTable;
Use Transaction - No
Next, copy the data into your table from Excel:
Action - TransferSpreadsheet
Transfer Type - Link (This does not bring the spreadsheet in, it just copies
the date)
Table Name - The name of the table you want to put the data in
File Name - The full path and file name of the spreadsheet you want to import
Has Field Names - Yes if your first row of data in Excel has field or column
names
Range - The name of the worksheet in your Excel file that you want.
You may want to turn warnings back or, or run your append query after that,
but I think you can take it from here. Post back if you need more help.
'green' said:
hi all, i have faced a problem in importing to the existing table
it show me this error:
"File" was unable to append all data to the table
The contents of fields in 0 record(s) were deleted, & 0 record(s) were lost
due to key violations.
However i lost over thousands of records. What had happened?
I have already checked the field type, it is the same as in excel.
I do thought of doing on a temporary table and do an append query to the
existing table instead as mentioned in other discussion.
But i need to automate the importation, which does not allow me to do so in
macro, as it require me to key in the table name. Is there any other way of
doing?
I'm really 'green' in access, pls help me in more simplified term
Thanks in advance