Run-time error '76': Path not found. Error occurred whilst using MkDir to create a file path, if it doesn't already exist.

  • Hi Everyone,


    I keep receiving the run-time error '76' saying path is not found & I can not understand why. I have tried using as many sites as possible to understand but it doesn't make sense.


    Background:

    I am writing the code in a userform & the individual who runs the macro has the option to change the file path (using combo boxes for the correct year & quarter which it is ran). I use an IF statement to check whether the directory already exists (majority of the time it doesn't) and then using MkDir to create my file path, which is the point it fails at. I have highlighted in red the point it fails. Please see short code below:


    The MkDir filepath is where it fails. Does anyone have any suggestions to why it may be failing? I will put the whole code below to help put somethings into context for you. (the me.tb_folderpath etc are the combo & text boxes where the individual can identify which paths they want the files to be saved in). If anyone would like more information/additional code please let me know.



    I have tested the filepath & it returns exactly what I want it too, so I am unsure how to resolve this issue.


    Thanks,


    Mel:)

  • MkDir will only make a directory within an existing directory. You cannot, for example, create a new directory and a subdirectory in one line, if that's what you are attempting?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Hi Roy,


    So using the example above me.tb_folderpath already exists (it is the companys L drive), so the additional folders I want to create are the year --> the quarter --> then the company code. So essentially I am trying to create 3 new folders all inside of each other. Are you saying first I would have to create the year then If statement again for the Qtr & then if statement for the company code?


    Thanks,


    Mel

  • Glad to help. :)


    PS It's Rory, not Roy.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why