473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

26
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
  7.  
  8.     DoCmd.SetWarnings False
  9.  
  10.     path = "\\v:\scc-e\irg\Monthly SAP\"
  11.  
  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
  24.  
Sep 20 '11 #1

✓ answered by pdebaets

I don't think that's a valid path. Try

Expand|Select|Wrap|Line Numbers
  1. path = "v:\scc-e\irg\Monthly SAP\"

6 41759
ADezii
8,834 Expert 8TB
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
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
Mihail
759 512MB
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
JAGster
26
Thank you all for your help. The path was not valid as pedebaets pointed out.
Sep 21 '11 #5
NeoPa
32,556 Expert Mod 16PB
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
JAGster
26
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

1
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...
28
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...
1
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...
5
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...
1
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"/>
5
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. ...
8
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 -...
23
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)...
1
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)...
3
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.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.