|
-
May 18th, 2013, 02:11 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Is this the right way
Hi
I wonder if this is going to be the way I think
Dim strFile As String
Dim FileCount As Integer
FileCount = 0
strFile = Dir(App.Path & "\backup\backup\PhoneTel.mdb" & Format(Now, "yymmdd_hhnn") & ".mdb")
Do Until strFile = ""
FileCount = FileCount + 1
strFile = Dir
Loop
' MsgBox FileCount & " file(s)"
if filecount => 4 then
Kill App.Path & "\backup\backup\PhoneTel.mdb??????_????.mdb"
else
sourcefile1 = App.Path & "\PhoneTel.mdb"
destinationfile1 = App.Path & "\backup\backup\PhoneTel.mdb" & Format(Now, "yymmdd_hhnn") & ".mdb"
FileCopy sourcefile1, destinationfile1
Bonzo
-
May 18th, 2013, 03:35 AM
#2
Re: Is this the right way
Code:
Const FILE_ATTRIBS = vbArchive Or vbReadOnly Or vbHidden Or vbSystem
Dim App_Path As String, strFile As String, FileCount As Integer
Dim SourceFile1 As String, DestinationFile1 As String
App_Path = App.Path 'Retrieve the Path property only once
'Make sure App_Path ends in a backslash
If Right$(App_Path, 1&) <> "\" Then App_Path = App_Path & "\"
strFile = Dir(App_Path & "backup\backup\PhoneTel.mdb??????_????.mdb", FILE_ATTRIBS)
Do While LenB(strFile) 'LenB(strFile) is faster than strFile = ""
FileCount = FileCount + 1
strFile = Dir
Loop
Debug.Print FileCount & " file(s)"
If FileCount >= 4 Then
On Error Resume Next 'Note that Kill fails if file is read-only
Kill App_Path & "backup\backup\PhoneTel.mdb??????_????.mdb"
On Error GoTo 0
End If
SourceFile1 = App_Path & "PhoneTel.mdb"
DestinationFile1 = App_Path & "backup\backup\PhoneTel.mdb" & Format$(Now, "yymmdd_hhnn") & ".mdb"
FileCopy SourceFile1, DestinationFile1
BTW, when posting code, please wrap them in [CODE] ... your code here ... [/CODE]. It preserves indenting making the code easier to read.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|