Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    527
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wildcard in VB code (AXP/Win 2K)

    Hello All,
    How do you use a wildcard inside VBA? I am trying this: (if strCustomerName = "AB*" then......) It is not picking up the customer AB.... I suspect it is looking for the string "AB*" I am looking for any customer that starts with AB. Does anyone have any suggestions?

    Thanks in advance!,
    Mark

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wildcard in VB code (AXP/Win 2K)

    Hi Mark,

    You could use the Left() function for something like that. For example:

    If Left(strCustomerName, 2) = "AB" Then
    ....


    HTH <img src=/S/salute.gif border=0 alt=salute width=15 height=20>

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Wildcard in VB code (AXP/Win 2K)

    MarkJ has a good answer as long as you restrict the search to a fixed number of characters at the beginning. If you were doing it in SQL you would need a Like "AB*" WHERE clause, but in VBA it works like the following syntax:

    MyResult = strCustomerName Like "AB*" where MyResult is a variable you dimension. With that syntax you can get cute and find things like *AB* and other asorted variations, and there are several other wildcard characters. Look in VBA help under Operators and you should find the LIKE operator. (I did this in XP, but I don't think there are any changes in this area. Check in any event.)
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •