Results 1 to 4 of 4
  1. #1
    Cecil is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Feb 2011
    Location
    Dallas, Texas
    Posts
    11

    Case statement doesn't work correctly

    I put in a couple watches, such as strSvcType and LEN(strSvcType). strSvcType equals "HOL". The string length of the variable, strSvcType is 3. As I was stepping through the code, I saw that the strSvcType variable was "HOL" (sorry for being a bit redundant here), yet the program did not go into that case; it completely bypassed it. Is there some bug in MS Access that causes it to bypass a CASE statement where the value of the variable is correct, yet the Case seems to ignore it? Or, did I miss something?

    A little later: I just received a Skype call from a friend about this. he told me to remove the strSvcType = from the Case and just have Case "HOL". Well, this is way different from Visual FoxPro. I do hope it works.



    Select Case strSvcType
    Case strSvcType = "HOL"
    strsql = strsql & "'" & strDOS & "', "
    strsql = strsql & "'BG', "
    strsql = strsql & "'BG', "

    Case strSvcType = "PAC"
    strsql = strsql & "'12/31/2999', "
    strsql = strsql & "'BG', "
    strsql = strsql & "'BG', "
    Last edited by Cecil; 05-16-2016 at 09:21 AM. Reason: spelling

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    ive never seen it skip it, but you are redundant
    The select case statement watches the variable
    you don't have to utilize that variable again...

    Code:
    Select Case strSvcType
            Case  "HOL"
            case "PAC"
    end select

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You would only use operators if you want to compare against numeric values.
    Case Is > 9
    Case Is = 9 - works, but is a bit redundant. Case 9 might be better.
    Case 5 To 9 - either 5,6,7,8 or 9 should cause this to be selected.

    Re: '12/31/2999' - does this actually work? You are delimiting what looks like a date as though it were a string.
    Last edited by Micron; 05-16-2016 at 07:45 PM. Reason: chgd case 5 to 6 to '5 to 9'
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Cecil is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2011
    Location
    Dallas, Texas
    Posts
    11
    I had a friend call me and tell me that I didn't need the redundancy. You are both right. Thanks Ranman256.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Time doesn't add up correctly
    By Larryg in forum Reports
    Replies: 2
    Last Post: 09-03-2015, 11:41 PM
  2. Replies: 8
    Last Post: 07-03-2015, 05:03 PM
  3. Replies: 5
    Last Post: 04-14-2014, 12:37 PM
  4. Just doesn't seem to work!
    By txmmoore in forum Reports
    Replies: 9
    Last Post: 01-16-2014, 11:39 AM
  5. Replies: 2
    Last Post: 07-23-2011, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums