Results 1 to 6 of 6

Thread: Error 52: Bad File Name

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    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

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    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.

  4. #4
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    706

    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.

  5. #5
    Lively Member
    Join Date
    May 2017
    Posts
    81

    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.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    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
  •  



Click Here to Expand Forum to Full Width