Using "Like*" in Select Case (SOLVED)

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Using "Like*" in Select Case (SOLVED)

Post by Michael Abrams »

Select Case rpt_name


If I want results of any Report Name beginning with the word Audit, how do I write that?

Pseudocode =
Case Like "AUDIT"*


Thank you.

Michael
Last edited by Michael Abrams on 03 Jul 2014, 18:34, edited 1 time in total.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Using "Like*" in Select Case

Post by Rudi »

AFAIK, you can't use the Like operator in a Select Case statement.
Try this:
If rpt_name Like "AUDIT*" Then
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using "Like*" in Select Case

Post by HansV »

Rudi is correct, Select Case doesn't work with Like, so you have to use If ... Then.

PS There is a sneaky way to use Like in a Select Case statement, but then you have to write out the conditions, so it's not really more efficient than a series of If Then ElseIf ... statements:

Code: Select all

    Select Case True
        Case [Report Name] Like "audit*"
            ...
        Case [Report Name] Like "yearly*"
            ...
        Case [Report Name] = "Summary"
            ...
        Case Else
            ...
    End Select
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Using "Like*" in Select Case

Post by Michael Abrams »

Select Case True actually works as I need it. Pretty slick !

Thank you guys .

Michael