Solved

Solving Run Time error 3011 with DoCmd.TransferSpreadsheet

Posted on 2013-12-18
6
2,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

690 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