Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i simplify ?

Status
Not open for further replies.

canett

Technical User
Jan 22, 2006
18
BG


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


note bappath, depotBl etc are paths
 
Sure, assuming DBl, DVa, DHA and so on are defined elsewhere, try this:
Code:
Option Compare Database
Option Explicit
Public StrSource  As String
Public Const strDest = bappath
Public Function CopyBackDepots()
Depot (DBl)
Depot (DVa)
Depot (DHa)
Depot (DPl)
Depot (DTa)
Depot (DTr)
Depot (DSz)
Depot (DRs)
Depot (DBs)
Depot (DSo)
End Function
Public Function Depot(strIn As String)
On Error Resume Next
StrSource = strIn
If Dir(StrSource, vbNormal) <> "" Then
Kill (StrSource)
End If
FileCopy StrSource, StrSource
End Function

[pc2]
 
I wonder the following works !
FileCopy StrSource, StrSource

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Good question PHV, apparently canett says it always did?

Good code mp9, great suggestion!

..and if I may, possibly another Idea.
I use arrays a lot for such repetition.


Public Function Depot()
On Error Resume Next

Dim varSource As Variant, x as Integer

varSource = _
Array("DBl", "DVa", "DHa", "DPl", "DTa", "DTr", _
"DSz", "DRs", "DBs", "DSo")

For x = 0 to Ubound(varSource)
StrSource = varSource(x)
If Dir(StrSource, vbNormal) <> "" Then
Kill (StrSource)
End If
FileCopy StrSource, StrSource
Next x

End Function

Only need to call One function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top