By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

VBA - Issues with Dir() and MkDir

100+
P: 140
Hi,

I inherited some code from a client, and have been having issues with it.

The first line was:
Expand|Select|Wrap|Line Numbers
  1. If Dir$(opath & "Requests\" & dirStr, vbDirectory) = "" Then
  2.  
I did a search in VBA help, and couldn't find 'Dir$' but did find 'Dir' I figured this was an instance where VBA had slightly less functionality than VB6/.net has...

Dir$ returns a string, while Dir returns a variant. Unsure if this is an issue or not.

The next line is the line that it blows up on:
Expand|Select|Wrap|Line Numbers
  1. MkDir opath & "Requests\" & dirStr
  2.  
Originally, he had:
Expand|Select|Wrap|Line Numbers
  1. MkDir (opath & "Requests\" & dirStr)
  2.  
But, it was hanging up there, so I removed the ( )s.
opath IS a real path AT runtime.
dirStr is a legal path as well.

Any ideas?

Thanks,
Sitko.
May 2 '08 #1
Share this Question
Share on Google+
3 Replies


kadghar
Expert 100+
P: 1,295
Hi,

I inherited some code from a client, and have been having issues with it.

The first line was:
Expand|Select|Wrap|Line Numbers
  1. If Dir$(opath & "Requests\" & dirStr, vbDirectory) = "" Then
  2.  
I did a search in VBA help, and couldn't find 'Dir$' but did find 'Dir' I figured this was an instance where VBA had slightly less functionality than VB6/.net has...

Dir$ returns a string, while Dir returns a variant. Unsure if this is an issue or not.
Its not a bug!, its a feature!,working it as a string is way faster than a variant, but you'll have to forget about some implicit type conversions (an insignificant draw back)

But if it makes you feel better, you can remove the $ freely. It'll still working in VBA, or you can use DIR$ in many other versions of VB too.

The next line is the line that it blows up on:
Expand|Select|Wrap|Line Numbers
  1. MkDir opath & "Requests\" & dirStr
  2.  
Originally, he had:
Expand|Select|Wrap|Line Numbers
  1. MkDir (opath & "Requests\" & dirStr)
  2.  
But, it was hanging up there, so I removed the ( )s.
opath IS a real path AT runtime.
dirStr is a legal path as well.

Any ideas?

Thanks,
Sitko.
Yes, this code should be run only once, because you're creating a new dir.
Once the Dir is created, you cannot create it again, so i'll show you an error.
Just make sure the dir doesnt exists before you create it, or an error handler might be of help too.

HTH

PS: yeah, parenthesis may be removed without a problem.
May 2 '08 #2

100+
P: 140
so, I guess the problem lies elsewhere...

Thanks,
Sitko.
May 2 '08 #3

Dököll
Expert 100+
P: 2,364
Might also consider telling us what you are trying to achieve, perhaps there's an idea here you can use...

You can submit the whole code for all to see, just in case someone is passing through;-)

See you soon!

Dököll
May 3 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.