Solved

Solving Run Time error 3011 with DoCmd.TransferSpreadsheet

Posted on 2013-12-18
6
1,889 Views
Last Modified: 2014-02-20
Can anyone see what is causing the run time error in my code? I realize it may be difficult without having the spreadsheet, but I am confident the naming is consistent between my code and the spreadsheet.  I have tried multiple files and locations, but I keep getting the error. When I hover my arrow over MyRange, it says empty. Thanks!

Function ImportExcelFile()

Dim MyDir As String
Dim MyFile As String
Dim MyYear As String
Dim MyMonth As String
Dim MyDay As String
Dim MyDate As String
Dim FileToGet As String
Dim shtName As String



MyDir = "//AvailableSummaries/"
MyYear = Format(Date, "yyyy")
MyMonth = Format(Date, "mm")
MyDay = Format(Date, "dd")
MyDate = MyYear & " " & MyMonth & "-" & MyDay
MyFile = MyDate & " Contractor Available Stock" & ".xls"
shtName = "'Contractor Available Inventory'!"
MyRange = "A1:D10000"
FileToGet = MyDir & MyFile


DoCmd.TransferSpreadsheet acImport, 8, "tblContractorAvailableInventory", FileToGet, True, shtName & MyRange


End Function

Open in new window

0
Comment
Question by:Dominator1025
  • 3
  • 2
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39727821
try this


DoCmd.TransferSpreadsheet acImport, 8, "tblContractorAvailableInventory", FileToGet, True, shtName & "!" & MyRange
0
 

Author Comment

by:Dominator1025
ID: 39727861
I still have the error.  However, the range is no longer empty.

Could there be any issues with excel version file types?  The Excel file is a Microsoft Excel Worksheet and I am using Access 2010.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39727889
try

changing 8 to 9


DoCmd.TransferSpreadsheet acImport, 9, "tblContractorAvailableInventory", FileToGet, True, shtName & "!" & MyRange
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:Dominator1025
ID: 39727894
Same error.  When I hover over acImport, I see it = 0.

What does this mean?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39728037
are sure you are getting the correct excel file ?

FileToGet = MyDir & MyFile

debug.print FileToGet   'Add this lines and verify if the file and path is correct.

if dir(MyDir & MyFile) <> "" then
    msgbox "File Exists"
    else
     msgbox " File Not found"
end if
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39728341
<<
MyDir = "//AvailableSummaries/"

>>

Double -check this.  

If you are dealing with a network folder, shouldn't the slashes be going in the opposite direction?


MyDir = "\\AvailableSummaries\"
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

839 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