Solved problem with Dir function

You have to look to see what tha variables contain? :(
Debug.Print FilePath and look to see what that is.

Access does not lie :)
 
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!
 
Please mark it Solved then.
 
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.
 
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.
 
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
 
1670014098571.png
 
Mine looks like this
 

Attachments

  • Screenshot_20221202-160037~2.png
    Screenshot_20221202-160037~2.png
    41.7 KB · Views: 96
And is that on the first page?
 
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?
 
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

Back
Top Bottom