Share via

Select Case not working.

Anonymous
2016-09-09T03:37:55+00:00

This Select statement parses to the CASE ELSE statement EVERY TIME.  Even though the IF..THENs parse correctly, the SELECT CASE does not.

I have added msgbox and temorary IF..THENs to verify that the values of sFileName are what I expect. 

They are.

Any ideas.  Wits end has been reached. 

'========================================

    Dim oFileSystem As Object

    Dim oFiles As Object

    Dim oSub As Object

    Dim sFileName As String

    Dim sFullName As String

    Dim iFileSize As Integer

    icount = icount + 1

    Set oFileSystem = CreateObject("Scripting.FileSystemObject")

    Set oFiles = oFileSystem.GetFolder(sDirPath)

    For Each oSub In oFiles.Files

        sFileName = oSub.name

        sFullName = sDirPath & "" & oSub.name

        lFileSize = oSub.Size

        ' Temporary statements to examine and verify sFileName

        If Right("   " & sFileName, 4) = ".txt" Then MsgBox ".txt"

        If InStr(sFileName, "shs_extract") > 0 Then MsgBox "What the? shs_extract"

        If IsNumeric(Left(sFileName, 5)) And Right("  " & sFileName, 4) = ".xml" Then MsgBox "What the? Number and XML"

        If iFileSize > 0 Then MsgBox "what the? zero size"

        Select Case sFileName

            '===================================================

        Case Right("   " & sFileName, 4) = ".txt"

            ' ignore the file as it cannot be a valid QDC submission.

            MsgBox ".txt file"

            '===================================================

        Case InStr(sFileName, "shs_extract") > 0

            ' If the file name contains the string 'shs_extract' then move

            ' it to the SHS folder.

            Filetodie = sFullName

            Name sFullName As sHomelessDir & sFileName & "." & Left(sFileName, 5)

            Call KillFile(Filetodie)

            MsgBox "Homeless file"

            '===================================================

        Case IsNumeric(Left(sFileName, 5)) And Right("  " & sFileName, 4) = ".xml"

            ' If the file name begins with a five digit number and is an xml file, it needs to be

            ' checked against the  table to see if it is valid and that it is active.

            ' REMOVED PROCESSING THINGS HERE.

         Case Else

            MsgBox "Exception"

            ' NOT AN EASILY PROCESSED FILE.  PUT IT IN THE UNACCEPTABLE SUBMISSION FOLDER

            Filetodie = sFullName

            Name sFullName As sIssuesDir & sFileName & ".Exception"

            Call KillFile(Filetodie)

        End Select

    Next oSub

    Set oFiles = Nothing

    Set oFileSystem = Nothing

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2016-09-09T06:16:38+00:00

    Change

    Select Case sFileName

    to

    Select Case True

    since the Case ... parts don't enumerate possible values for sFileName, but are conditions in themselves.

    Or use Ifs and ElseIfs.

    Was this answer helpful?

    0 comments No comments