Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import Excel spreadsheet into Access

Status
Not open for further replies.

moobcinos

MIS
Jan 3, 2008
4
US
Hi All,

I am a newbie to VBA coding and am trying to do a relatively simple thing. I am attempting to automate the process of importing an Excel spreadsheet into an Access database, run a couple of queries against the data in the newly imported table, then export the resulting reports to Word format if possible.

Below is the code I am using:
***********************************************************
Function GET_EXPORT_DATA()
On Error GoTo GET_EXPORT_DATA_Err

CurrentDb.Execute "Delete * from [Export Scorecard]"
DoCmd.TransferSpreadsheet acImport, 8, "Export Scorecard", "T:\BIM\BPM\_ExportDB", True, ""
DoCmd.OpenQuery "CTE Query", acViewNormal, acEdit
DoCmd.OpenQuery "DayToPGI", acViewNormal, acEdit


GET_EXPORT_DATA_Exit:
Exit Function

GET_EXPORT_DATA_Err:
MsgBox Error$
Resume GET_EXPORT_DATA_Exit

End Function
******************************************************

The problem is that when I try to run it, I get the error message below:

'The Microsoft Jet Engine cannot open the file “”. It is opened exclusively by another user, or you need permission to view the file.'

Any assistance provided would be greatly appreciated. Thanks!
 
Take the "" out of the last argument. Access doesn't know what to do with that.

Paul
 
Double check that "T:\BIM\BPM\_ExportDB" is the name and path of the file to be imported.
 
Have you checked the folder permissions?
 
Is the name of the file _ExportDB or _ExportDB.xls?
 
@Remou - I thought it may be the folder security as well, so I copied the spreadsheet to my local machine and modified the code to point to it. I still got the same error

@bubba100 - I noticed that too after the fact, so I changed it to _ExportDB.xls, which is the name of the file. I still got the same error
 
This is what my code looks like now. I moved the spreadsheet I'm trying to import onto my Desktop just for testing to see if it was a security issue on the network drive in which it resides.
***********************************************************
Option Compare Database

Function GET_EXPORT_DATA()
On Error GoTo GET_EXPORT_DATA_Err

CurrentDb.Execute "Delete * from [Export Scorecard]"
DoCmd.TransferSpreadsheet acImport, 8, "Export Scorecard.xls", "C:\Documents and Settings\DWALK18\Desktop", True
DoCmd.OpenQuery "CTE Query", acViewNormal, acEdit
DoCmd.OpenQuery "DayToPGI", acViewNormal, acEdit


GET_EXPORT_DATA_Exit:
Exit Function

GET_EXPORT_DATA_Err:
MsgBox Error$
Resume GET_EXPORT_DATA_Exit

End Function
***********************************************************
 
What about this ?
DoCmd.TransferSpreadsheet acImport, 8, "Export Scorecard", "C:\Documents and Settings\DWALK18\Desktop\_ExportDB.xls", True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That is a bit tangled. The syntax is:

DoCmd.TransferSpreadsheet [transfertype][, spreadsheettype], tablename, filename[, hasfieldnames][, range]

so

[tt]DoCmd.TransferSpreadsheet acImport, 8, "Export Scorecard", "C:\Documents and Settings\DWALK18\Desktop\Export Scorecard.xls", True[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top