Solved problem with Dir function (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
You have to look to see what tha variables contain? :(
Debug.Print FilePath and look to see what that is.

Access does not lie :)
 

poppajim713

New member
Local time
Today, 02:04
Joined
Dec 1, 2022
Messages
20
I tried
Code:
 Kill Trim(FilePath)
to see if what I'd get. I got an error 53, file not found.
I am hanging my head in shame. I found the problem. I was creating a backup in one function that used
Code:
 Format(Date, "m-d-yy")
to create the name of the file, but in another function to delete the oldest file, from 3 days ago, I used the DateAdd function but didn't format that. So, I was comparing 12-2-22 to 12-2-2022. It's working fine now. I'm sorry, but thanks to all. The suggestion to use debug.print really helped. When I saw the 2 together is when I realized what a bonehead I was. Thanks again!
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
Please mark it Solved then.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
I'm not sure how
Top right of the thread, should be thread tools or something similar. Only the O/P can see it?

Edit: Actually, there is a Solved toggle button top right, next to an Unwatch button.
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:04
Joined
Mar 14, 2017
Messages
8,777
I would strongly recommend switching to use Createobject("scripting.filesystemobject").fileexists("path to file") (yields true or false) instead.
For this purpose.

Dir is a very nuanced, command that can be used in a multitude of different fascinating ways, much more than it seems at first glance.

FYI, back when I used DIR to check file existence, I usually tested things like this:

If Dir(path to file)="" then [doesn't exist]
Rather than assigning Dir(path) as the assigned value to a string variable - ESPECIALLY with 'on error resume next' in front of it, which you should immediately remove while troubleshooting especially as well as permanently, as all it does is COVER UP errors that might HELP you figure out what is wrong - the absolute last thing you'd want right now!

The final way you settled (solved) on doing, that actually checks for the existence of any files matching that wildcard description - which isn't really an exact test you originally wanted, and probably thus isn't an ideal solution.
 

poppajim713

New member
Local time
Today, 02:04
Joined
Dec 1, 2022
Messages
20
I would strongly recommend switching to use Createobject("scripting.filesystemobject").fileexists("path to file") (yields true or false) instead.
For this purpose.

Dir is a very nuanced, command that can be used in a multitude of different fascinating ways, much more than it seems at first glance.

FYI, back when I used DIR to check file existence, I usually tested things like this:

If Dir(path to file)="" then [doesn't exist]
Rather than assigning Dir(path) as the assigned value to a string variable - ESPECIALLY with 'on error resume next' in front of it, which you should immediately remove while troubleshooting especially as well as permanently, as all it does is COVER UP errors that might HELP you figure out what is wrong - the absolute last thing you'd want right now!

The final way you settled (solved) on doing, that actually checks for the existence of any files matching that wildcard description - which isn't really an exact test you originally wanted, and probably thus isn't an ideal solution.
Thanks for the help
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
1670014098571.png
 

poppajim713

New member
Local time
Today, 02:04
Joined
Dec 1, 2022
Messages
20
Mine looks like this
 

Attachments

  • Screenshot_20221202-160037~2.png
    Screenshot_20221202-160037~2.png
    41.7 KB · Views: 52

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
And is that on the first page?
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:04
Joined
Sep 21, 2011
Messages
14,310
Just checked. It's on both
Ok, forget it then. :)

Not sure why you do not have that button as you are the O/P. :unsure:

I can only *guess* it might be because it is in the Introduce Yourself forum, and nothing really should be solved there?

Perhaps @Jon can confirm?
 

poppajim713

New member
Local time
Today, 02:04
Joined
Dec 1, 2022
Messages
20
Ok, forget it then. :)

Not sure why you do not have that button as you are the O/P. :unsure:

I can only *guess* it might be because it is in the Introduce Yourself forum, and nothing really should be solved there?

Perhaps @Jon can confirm?
That makes sense. Rookie move on my part.
 

Users who are viewing this thread

Top Bottom