Results 1 to 5 of 5

Thread: [RESOLVED] IF Statements

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [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
    Last edited by Kubull; Jan 13th, 2010 at 06:17 AM.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    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.

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Re: IF Statements

    Awsome Works like a charm! many thanks

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