-
[RESOLVED] IF Statements
Hi All,
I'm having trouble trying to omit some user folder off of a script we use to distribute file to all staff.
The below script is used to distribute a single database to multiple folders which users here store their files and such.
I need to omit some users from receiving this new file as their systems haven't been upgraded.
So far I have only added:
Code:
If InStr(f1.Name, "Dobbs, Terry" & "Seacole, Steve" & "Patel, Ash" & "Jenkins, Tricia") = ture Then
Resume Next
End If
But it doesn't like it, Any help would be greatly appriciated.
Code:
Dim fso, f, fc, f1, SourceFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFile = fso.GetFile("H:\K Drive\Databases\NewLiveActs.mde")
Set f = fso.GetFolder("H:\K Drive\")
Set fc = f.SubFolders
For Each f1 In fc
If InStr(f1.Name, ",") > 0 Then
On Error Resume Next
SourceFile.Copy f1 & "\Databases\"
If Err.Number <> 0 Then
Select Case Err.Number ' Evaluate error number.
Case 70
mystr = mystr & f1 & " - Permission Denied" & vbNewLine 'add to string here
Case 76
mystr = mystr & f1 & " - Path not found" & vbNewLine ' add to string here
Err.Clear
Case Else
End Select
Else
End If
On Error GoTo 0
End If
If InStr(f1.Name, "Dobbs, Terry" & "Seacole, Steve" & "Patel, Ash" & "Jenkins, Tricia") = ture Then
Resume Next
End If
Next
mystr = mystr & " -- File Distribution Completed -- " & vbNewLine
Set f1 = fso.CreateTextFile("H:\K Drive\NewLiveactsScriptLog.txt", True)
f1.Write mystr
f1.Close
Set f1 = Nothing
Set fso = Nothing
-
Re: IF Statements
Try this
Code:
If InStr(f1.Name, "Dobbs, Terry") Or _
InStr(f1.Name, "Seacole, Steve") Or _
InStr(f1.Name, "Patel, Ash") Or _
InStr(f1.Name, "Jenkins, Tricia") Then
'~~> For Testing
MsgBox "Hello"
End If
-
Re: IF Statements
Thanks Coolsid,
The msgbox comes up, how would I now get the script to skip them? not sure resume next does the job.
-
Re: IF Statements
Code:
Dim fso, fo, sf, fi, ErrStr, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set fi = fso.GetFile("H:\K Drive\Databases\NewLiveActs.mde")
Set fo = fso.GetFolder("H:\K Drive\")
ErrStr = ""
For Each sf In fo.SubFolders
If InStr(sf.Name, ",") > 0 Then
Select Case sf.Name
Case "Dobbs, Terry"
Case "Seacole, Steve"
Case "Patel, Ash"
Case "Jenkins, Tricia"
Case Else
On Error Resume Next
fi.Copy sf.Path & "\Databases\"
If Err.Number <> 0 Then
ErrStr = ErrStr & sf.Name & " - " & Err.Description & vbNewLine
Err.Clear
End If
On Error GoTo 0
End Select
End If
Next
If ErrStr <> "" Then MsgBox ErrStr
-
Re: IF Statements
Awsome Works like a charm! many thanks :)