Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Jan 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can i simplify (Access 2000)

    I have the following function that works. Could i rationalize it further,make it more simple or avoid repetition of the commands?


    Option Compare Database
    Option Explicit
    Public StrSource As String
    Public Const strDest = bappath
    Public Function CopyBackDepots()
    DepotBl
    DepotVa
    DepotHa
    DepotPl
    DepotTa
    DepotTr
    DepotSz
    DepotRs
    DepotBs
    DepotSo
    End Function



    Public Function DepotBl()
    On Error Resume Next
    StrSource = DBl
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotVa()
    On Error Resume Next
    StrSource = DVa
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotHa()
    On Error Resume Next
    StrSource = DHa
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotPl()
    On Error Resume Next
    StrSource = DPl
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotTa()
    On Error Resume Next
    StrSource = DTa
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotTr()
    On Error Resume Next
    StrSource = DTr
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotSz()
    On Error Resume Next
    StrSource = DSz
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotRs()
    On Error Resume Next
    StrSource = DRs
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotBs()
    On Error Resume Next
    StrSource = dbs
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function
    Public Function DepotSo()
    On Error Resume Next
    StrSource = DSo
    If Dir(StrSource, vbNormal) <> "" Then
    Kill (StrSource)
    End If
    FileCopy StrSource, StrSource
    End Function


    where bappath, depotBl, etc are paths

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can i simplify (Access 2000)

    I don't understand what you're doing: the line

    FileCopy StrSource, StrSource

    will fail because (1) you have just deleted the file designated by strSource, and (2) you're trying to copy a file to itself.

    Which file do you want to delete and which file do you want to copy?

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Leuven, Vlaanderen, Belgium
    Posts
    322
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Re: Can i simplify (Access 2000)

    Hi, Cannett,
    no answer to your question but an suggestion: add for each function a comment line with a brief description of what it's intended for.
    Such a clarification makes it maybe also easier to review & answer your question (but the latter is just talking for myself - no too experienced programmer).
    Take care,
    Hasse

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Can i simplify (Access 2000)

    As a general point, you only really need one Depot function if you rewrite it to accept string arguments (I'm assuming, as per Hans' post, that there should be separate file paths for the copy from and to):
    <pre>Public Function Depot(strPathFrom as String, strPathTo as String)
    On Error Resume Next
    If Dir(strPathTo, vbNormal) <> "" Then
    Kill (strPathTo)
    End If
    FileCopy strPathFrom, strPathTo
    End Function
    </pre>


    You would then change the calls to the function to something like <code>Depot(DBI_old_path, DBI_new_path )</code>

    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •