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

Check for Backup file before deleting

P: n/a
I have a database that does an auto backup of some data before
closing. I also have it set up to delete all backup files older than
5 days. I can't figure out how to check if the file is there and to
keep from getting the "File not found" error.

Any help is greatly appreciated,

Thank you,
ShyGuy
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Search in the newsgroup archives for a thread 'Detecting If Table
Exists'. There's a handy function in there by David Fenton called
'DoesObjectExist' that I use quite often.

Let us know if you need any help with it (or can't find it)!

-------
LoopyNZ
-------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2

P: n/a
I apologise, I should read the question properly before replying.
*SLAPS HERSELF*

New answer: Look in the help at the 'Dir' function.

Excerpt: Dir returns the first file name that matches pathname. To get
any additional file names that match pathname, call Dir again with no
arguments. When no more file names match, Dir returns a zero-length
string ("").

-------
LoopyNZ
-------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
Thanks for the quick reply, I tried the Dir function, but I'm afraid
I'm lost. I tried to use it in an if statement and it doesn't seem
to work. The Backup files are saved in the following format

DB Backup 8-27-2004.mdb

I use the following to create each days backup name.

"C:\DB Backup " & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now())
& ".mdb"

I tried setting Myfile to the above, then
If myfile = True then Kill "the file"
but it doesn't work.

I know I'm doing something wrong but don't know enough to figure it
out.

Thanks for your help.

On 27 Aug 2004 14:52:54 GMT, LoopyNZ <Lo*****@NOguruSPPAM.net.nz>
wrote:
I apologise, I should read the question properly before replying.
*SLAPS HERSELF*

New answer: Look in the help at the 'Dir' function.

Excerpt: Dir returns the first file name that matches pathname. To get
any additional file names that match pathname, call Dir again with no
arguments. When no more file names match, Dir returns a zero-length
string ("").

-------
LoopyNZ
-------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 13 '05 #4

P: n/a
ShyGuy <sh****@shytown.com> wrote in message news:<ql********************************@4ax.com>. ..
Thanks for the quick reply, I tried the Dir function, but I'm afraid
I'm lost. I tried to use it in an if statement and it doesn't seem
to work. The Backup files are saved in the following format

DB Backup 8-27-2004.mdb

I use the following to create each days backup name.


I tried setting Myfile to the above, then
If myfile = True then Kill "the file"
but it doesn't work.

I know I'm doing something wrong but don't know enough to figure it
out.


Shy,

try something like this:

Public Function FileExists(ByVal strFilePath As String) As Boolean
If Len(Dir(strFilePath, vbNormal)) Or Len(Dir(strFilePath, vbArchive)) Then
FileExists = True
Else
FileExists = False
End If
End Function

then your routine would be something like:
'watch the WRAP!
dim strFileName as string
strFileName =
"C:\DB Backup " & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & ".mdb"

if FileExists(strFileName) then
kill strFileName
end if
'--put your code to save your backup copy here somewhere...
Nov 13 '05 #5

P: n/a
Thank you so much. It worked great!!

Shyguy
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.