james_halliwell
Registered User.
- Local time
- Today, 11:54
- Joined
- Feb 13, 2009
- Messages
- 211
HI,
please could someone help me out, i am trying to download an excel document from a url and the import it into a table i can successfully download the file to my desktop but when i try to import it i get the below error
the Microsoft office access database engine cannot open or write to file 'C:\documents and settings\JHalliwe\Desktop\' it is already opened exclusively by another user, or you need permission to view and write its data
i have checked and the excel book is not open ( i think its trying to open while its still downloading is there away around this
many thanks (code below is what i am using)
please could someone help me out, i am trying to download an excel document from a url and the import it into a table i can successfully download the file to my desktop but when i try to import it i get the below error
the Microsoft office access database engine cannot open or write to file 'C:\documents and settings\JHalliwe\Desktop\' it is already opened exclusively by another user, or you need permission to view and write its data
i have checked and the excel book is not open ( i think its trying to open while its still downloading is there away around this
many thanks (code below is what i am using)
Code:
Dim strUserName As String
strUserName = Environ("UserName")
Dim FolderLoc As String
FolderLoc = "C:\Documents and Settings\" & strUserName & "\Desktop\"
Dim StFile As String
Dim MySelect
MySelect = Forms!FrmIndex!Text134
If MySelect = "Joints" Then
StFile = Dir$("C:\Documents and Settings\" & strUserName & "\Desktop\DO_GS1.xls")
ElseIf MySelect = "Codman" Then
StFile = Dir$("C:\Documents and Settings\" & strUserName & "\Desktop\COD_GS1.xls")
End If
DoCmd.OpenForm "FrmLoading", acNormal
Dim myURL As String
myURL = "http://www.commerce.jnjgateway.com/pdfs/GS1/DO_GS1.xls"
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False
WinHttpReq.Send
myURL = WinHttpReq.ResponseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.ResponseBody
oStream.SaveToFile (FolderLoc & "DO_GS1.xls ")
oStream.Close
End If
CurrentDb.Execute "DELETE * FROM TblGS1Conversion_temp"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "TblGS1Conversion_temp", "C:\Documents and Settings\" & strUserName & "\Desktop\" & StFile, True