Log in

View Full Version : Solved: VBA MkDir error???



andrew93
12-04-2005, 02:44 AM
Hi Everyone

I had a particular piece of code that was working but I recently moved my database to another directory and this particular piece of code is no longer working.

This is the code :

'Set the new save path to a sub-directory
strPathNew = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\", , vbTextCompare))
strPathNew = strPathNew & "Invoices\"

'Check the correct path has been returned - used for debugging purposes
MsgBox strPathNew

'If the sub-directory does not exist then create it
If Dir(strPathNew, vbDirectory) = "" Then
MkDir strPath '< THIS IS WHERE THE ERROR OCCURS
End If

Previously, if the sub-directory called 'Invoices' did not exist, then the routine would create it. Now that I have shifted the database, I'm getting an error on the MkDir line I indicated above. The error is number 76 and the description is 'path not found'. All I did was move the database from the 'My Documents' folder into a folder within 'My Documents' called 'Databases' and now this piece of code doesn't work. All of the code prior to this works perfectly. I've done a search on Google and this forum without luck and am looking for pointers.

Any thoughts as to what has gone wrong?

TIA, Andrew

TonyJollans
12-04-2005, 03:59 AM
Hi Andrew,

I suspect this is your errorIf Dir(strPathNew, vbDirectory) = "" Then
MkDir strPath '< THIS IS WHERE THE ERROR OCCURS
End Ifand you should change it to thisIf Dir(strPathNew, vbDirectory) = "" Then
MkDir strPathNew '< THIS IS WHERE THE ERROR OCCURS
End If

andrew93
12-04-2005, 12:04 PM
As Homer Simpson would say "D'Oh!"

I guess I changed more than just moving the database and the incorrect name didn't come to light until I moved the database.

Thank you for the speedy response. It works fine now.

:thumb

TonyJollans
12-04-2005, 12:21 PM
My pleasure!

It is so much easier for an third eye to spot the obvious that one can blind to.