-
Oct 15th, 2019, 02:12 PM
#1
Thread Starter
Fanatic Member
Error 52: Bad File Name
Hello vbforums
This code sometimes throws the following error.
Error 52: Bad File Name or Number Error
Code:
Dim P As Long
Dim leNombre As Long
P = FreeFile
Open DBPath & "\ficN.txt" For Output As P
Print #P, leNombre
Close (P)
Any idea please
thanks
-
Oct 15th, 2019, 02:25 PM
#2
Re: Error 52: Bad File Name
Well that depends on what is stored in dbPath. Typically that message would indicate a bad [invalid or nonexisting] path\file name
If dbpath is empty then it would likely give an access denied error instead as it would be trying to create a file in the root and that is by default not allowed under systems newer than XP.
-
Oct 15th, 2019, 02:41 PM
#3
Thread Starter
Fanatic Member
Re: Error 52: Bad File Name
thank you DataMiser
the dbPath is defined in the Sub Main
The problem is that I got the error very rarely.
-
Oct 15th, 2019, 03:30 PM
#4
Fanatic Member
Re: Error 52: Bad File Name
Use Debug.Print before Open. DBPath probably has a subfolder that doesn't exist, or was deleted. There are many FolderExist routines out there to make sure that the folder exists, and create it if needed. You may also want to search for SHCreateDirectoryEx(), which creates a directory tree in case more than one subfolder doesn't exist.
-
Oct 16th, 2019, 01:22 AM
#5
Lively Member
Re: Error 52: Bad File Name
Also, what value is P ? The full text of error 52 is Bad File Name or Number. IIRC there is a maximum number of open files limit.
A leak of file numbers (files not being properly closed) elsewhere in your code could cause FreeFile to exceed a limit.
Last edited by MikeSW17; Oct 16th, 2019 at 01:53 AM.
-
Oct 17th, 2019, 06:11 AM
#6
Thread Starter
Fanatic Member
Re: Error 52: Bad File Name
Thank you MikeSW17
Do you haveany suggestions please?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|