Results 1 to 2 of 2

Thread: [RESOLVED] Is this the right way

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Resolved [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

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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
  •  



Click Here to Expand Forum to Full Width