Solved

Import Excel Spreadsheet into Access via VBA

Posted on 2008-09-29
12
1,092 Views
Last Modified: 2013-11-27
I am trying to import a file from Excel into Access via a command button on a form.  I keep getting the following error:
Run-time error '3274':
External table is not in the expected format.

However if I run it with the Excel File open, it works perfectly.  

Any suggestions on how to do it without having the file open?

p.s.  See attached code for my command button

Thanks,
Matheinjoe
Private Sub cmdImport_Click()
If IsNull(Me.txtFileName) Or Len(Me.txtFileName & "") = 0 Then
    MsgBox "please select the excel file"
    Me.cmdSelect.SetFocus
    Exit Sub
End If
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Import", Me.txtFileName, True
 
End Sub

Open in new window

0
Comment
Question by:matheinjoe
[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
  • 6
  • 6
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22597154

the codes are good...

what is the value in Me.txtFileName?
0
 

Author Comment

by:matheinjoe
ID: 22597333
The Value in Me.txtFileName is the path to my file.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22597375
can you post the value?   "c:\myfolder\myexcel.xls"

is this happening to all other files that you select ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:matheinjoe
ID: 22597454
Me.txtFileName = "C:\Documents and Settings\jmathei\Desktop\OR_TEST_DATA.xls"

It is happening on every xls file.

I found something on the web that stated to change  the "acSpreadsheetTypeExcel9 to the correct version of my Excel.  My version is 11, but I get a Compile Error: Variable Not Defined when I change that.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 22597534
try just using the default, use this line


DoCmd.TransferSpreadsheet acImport, , "Import", Me.txtFileName, True
 
0
 

Author Comment

by:matheinjoe
ID: 22597564
Same Error
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22597578
from vba code window

DEBUG >Compile

did you get an error ? if yes, paste the error message and pertinent info
0
 

Author Comment

by:matheinjoe
ID: 22597635
No Error Message When I Select Debug>Compile.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22597683
do a decompile

http://www.granite.ab.ca/access/decompile.htm

follow the instruction from the link

then create a blank db and import all the objects to the new db
0
 

Author Comment

by:matheinjoe
ID: 22597812
That didn't work either.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22597837
can you attach your excel file and db.

check the Attach File below
0
 

Author Comment

by:matheinjoe
ID: 22597927
Ok, as I was saving you a test file, I realized the file format was Unicode Text.  I saved it as an Excel file and it works properly now.  But this brings up another issue.  How would I import a Unicode Text file?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Report Expression 4 26
MS Access How can I change my confirm pop up to display my data field in lieu of the ID? 7 25
Access Query: Text to Date 10 31
Parameter Query 33 50
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

756 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