473,889 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix code for Run-time Error 52, Bad file name or number?

26 New Member
I don’t know VBA but have been using Access for awhile using tables, queries, forms and macros. I am trying to automate importing a number of Excel 2007 spreadsheets into an Access 2007 table. The import will be done each month, but the number of spreadhseets could be different. The spreadsheets will all be saved to the same folder. I need to import all the spreadsheets in the folder into the same table. I found VBA code in a different post that was written for Excel 2003 and Access 2003. I changed the path, the table name and the spreadsheet type but when I run the code I get Run-time error 52, Bad file name or number.

When I debug the code, it highlights the line this line --strFile = Dir(path & "*.xlsx").

Expand|Select|Wrap|Line Numbers
  1. Function getData()
  2. Dim strFile As String 'Filename
  3. Dim strFileList() As String 'File Array
  4. Dim intFile As Integer 'File Number
  5. Dim filename As String
  6. Dim path As String
  8.     DoCmd.SetWarnings False
  10.     path = "\\v:\scc-e\irg\Monthly SAP\"
  12.     strFile = Dir(path & "*.xlsx")
  13.     While strFile <> ""
  14.          'add files to the list
  15.         intFile = intFile + 1
  16.         ReDim Preserve strFileList(1 To intFile)
  17.         strFileList(intFile) = strFile
  18.         strFile = Dir()
  19.     Wend
  20.     If intFile = 0 Then
  21.         MsgBox "No files found"
  22.         Exit Function
  23.     End If
Sep 20 '11 #1
6 42050
8,834 Recognized Expert Expert
The Code seems fine, I think the problem lies in the path Variable Assignment, namely:
Expand|Select|Wrap|Line Numbers
  1. path = "\\v:\scc-e\irg\Monthly SAP\"
P.S. - You may also wish to change the path String Variable to strPath so as to avoid confusion with the PATH used to set the Search Path for Executable Files, namely:
Expand|Select|Wrap|Line Numbers
  1. Dim strPath as String
  2. strPath = "\\v:\scc-e\irg\Monthly SAP\"
Sep 21 '11 #2
16 New Member
I don't think that's a valid path. Try

Expand|Select|Wrap|Line Numbers
  1. path = "v:\scc-e\irg\Monthly SAP\"
Sep 21 '11 #3
759 Contributor
Some more help:

When you are in DEBUG mode (your code stops because the error in line 12) press CTRL+G.
This will open the DEBUG window.
In this window type ?strPath and press ENTER. Now you can see the contain of strPath variable.
Is this value what you expect ?

I assume that you change the name for Path into strPath as ADezii teach you.
Sep 21 '11 #4
26 New Member
Thank you all for your help. The path was not valid as pedebaets pointed out.
Sep 21 '11 #5
32,584 Recognized Expert Moderator MVP
I think you possibly missed that ADezii had already made that point in his post, but he has so many Best Answers already I doubt he'll miss an extra one ;-)
Sep 26 '11 #6
26 New Member
Yes ADezil pointed out that the path was the issue, but pdebaets gave me the correct path. Specifically the need to remove the backslashes at the very start of the path.
Oct 6 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Rob | last post by:
We are an ASP and are converting our application from VB to VB.NET. Our web farm is a mix of older dual processor 1.2GHz servers and newer dual processor 3.0GHz Xeon servers. When we originally got the new 3.0GHz boxes our VB code thrived on them, dramatically outperforming our 1.2GHz boxes at every load level. Now with the .NET code it appears that under light to moderate load, our 1.2GHz servers are out performing our 3.0GHz boxes. ...
by: n00m | last post by:
When I double-click on "some.py" file console window appears just for a moment and right after that it's closed. If this script is started from inside of IDLE (F5 key) then it executes as it should be (e.g. executing all its print statements). Any ideas? OS: Windows; Python 2.3.4. Thanks.
by: David T. | last post by:
Is there such a thing as a static constructor of an assembly? In other words is there code that is called when the assembly is loaded? There must be. Is there a way to customize this code? Is there a "DllMain" that is called that code can be written to (i.e. customized)? I am trying to have a message displayed when an assembly I've written is loaded into an executable that a user writes.
by: Brian Henry | last post by:
is there a way to make a procedure run on every page universally? like for a security check type thing.. to make sure someone has access to that page, run a security check method for each page the viewer visits, check to see if they have access if they do let them see it if not redirect them? thanks
by: Daves | last post by:
if I have a control in my aspx Page, can I set it's events to run code in the global (or even masterpage) class? Something like <asp:control OnInit="Global.EventCode"/>
by: dbuchanan | last post by:
Hello, I can find no reason for this code to run twice. Can you help me? It may have something to do with it being a overrides sub but stepping through during debug does *not* bear this out. In the base class form... \\
by: Scott Emick | last post by:
I am using the following to compute distances between two lat/long coordinates for a store locator - (VB .NET 2003) it seems to take a long time to iterate through like 100-150 locations - about 10-15 seconds...I want to make the code faster. I changed it to be multi-threaded, and it doesn't really make it any faster. The bottleneck seems to be with the math computations. Any ideas like changing my data types or other ideas etc would...
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80) return s def descrambleLine(line):
by: suchi123 | last post by:
Hi all, i have created a Calender user control which can run only IE.but i want the code for mozila,,,, the code i placed here.... /* hides <select> and <applet> objects (for IE only) */ function hideElement( elmID, overDiv )
by: ahd2008 | last post by:
Hi, Can anyone tell me how to dipaly a message if a VBA code run successfully. Also, if you can recommend a good book that demonstrates the methods of handling errors on VBA.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.