Solved

Import Excel Spreadsheet into Access via VBA

Posted on 2008-09-29
12
1,090 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
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to execute an access 2007 module from vb6 2 35
sql statement - 9 24
User Level Security 6 38
Turn off MS Access Default=0 for Numerics 6 25
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

770 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