Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Import Excel Spreadsheet into Access via VBA

Posted on 2008-09-29
12
Medium Priority
?
1,099 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

772 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