upload an excel file and convert to access table

ramesh

Registered User.
Local time
Today, 07:42
Joined
May 18, 2002
Messages
25
hai friends

if any one uploads the excel file with 3 colums filled up and then uploads the .xls file to my site .... in my site i have to read the xls file and convert the data to a new table or to a table with existing records.
please help me in doing this...
ramesh.s
 
Look up the TransferSpreadsheet Method/Action to get you started.
 
Your question is only unclear in one way. New vs. Existing table. When you say "or" do you suggest that you might have to do either import, or that you don't care which one you have to do in order to get the data into your database?


In any case, the import operation (done manually) is based on the menu operation File>>Get External Data>>Import...

which leads you into an "Import Wizard." The wizard can read the .XLS file for you and can figure out what each column should be in order to do the import correctly. The wizard can detect and import individual spreadsheets by name.

The corresponding function in a macro or in VBA code using DoCmd is called TransferSpreadsheet, which can be looked up in the Help files under that particular name (as an Action.) Depending on your version of Access, some folks have reported problems with importing other than the first spreadsheet in a given workbook when using the DoCmd action.

OK, a couple of generic pitfalls to worry about.

1. If you import to a new table, the format of each field depends on approximately the first 10 rows of the spreadsheet. If you have a numeric column for approximately 10 or so rows, then have text in that column, you'll get import errors if you are going into a new table. So in that case, you might have to build a new (but empty) table, then import (APPEND) to that table.

2. If you let Access create a new table and it detects the need for text import, it will probably try to make text fields 255 bytes long - unless you have previously adjusted your default table setup for text fields (in the Tools>>Options dialog box.) So you might have to go back into design mode post-import and reduce the size of the fields. This overly large text size won't make a difference to Access, but might affect any other databases you use via ODBC from Access, if this dataset becomes part of what you would forward to another DB server.

3. Access and Excel often take different views of dates. You might do better to first import date fields (if you have any) as text, then go back in design mode to change the format to Date field type.

4. Access will want to add a primary key for you. For the initial import, you might do better to have NO key, then go back into design mode later to add one after you know whether you have unique values in the chosen row. If you specify a particular column as your primary key BEFORE the import, it had better be unique or you will exclude some rows.

Other than that, I've not had major problems importing a spreadsheet into an Access table.
 
The_Doc_Man:

Thanks for the tips.
I am having trouble with the first generic pitfall you mentioned.
Could you please help me out with the syntax/code for the method you suggested as a workaround for importing spreadsheets with text in fields of other data types?

I would think the process to be simple, but I don't know how to begin creating a table from VBA with all-text field types,
much less how to append an external .XLS upon its import.
 

Users who are viewing this thread

Back
Top Bottom