Case statement to change a row source

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

    Case statement to change a row source

    I would like to use a case statement to change the row source in a form. The row source would change depending on a variable that can also change.
    if the variable contains the words "Wild Group" then the row source would change, if it didn't then it would be something else.
    I tried an If statement but it didn't like the Like "*Wild Group*"
    Code:
    If VWGName like "*Wild Group*" then
    Any help would be appreciated.
    Thanks
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Forms don't have a Row Source property. It does have the Record Source property.

    Anyway, I don't think that Like is a VBA keyword like it is in SQL. Try the following:
    Code:
    If InStr(VBGName, "Wild Group") > 0 Then

    Comment

    • CD Tom
      Contributor
      • Feb 2009
      • 495

      #3
      I was able to figure it out. I should probably work a little longer before posting a question. Thanks for your reply.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        FYI Like is supported by both SQL and VBA.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          I didn't know that. Thanks for the FYI NeoPa!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32661

            #6
            No worries Seth. I was telling my son only today that VBA (and SQL) comparisons are much more flexible than a single wildcard character. In fact care must be taken when using Like if the data has '[' characters in it such as Fields and Objects often do within SQL.

            For instance, a field name in a table could be [A B]. Search for that within a Like string and you'll match any single character of A, B or space. Powerful, but confusing for the unwary.

            Comment

            Working...