Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Import Excel Spreadsheet into Access via VBA

Posted on 2008-09-29
12
Medium Priority
?
1,096 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 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