Compare two Strings in Access using VBA

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Weiler

    Compare two Strings in Access using VBA

    I'm a relative newbie to VBA and I am STUMPED.

    I'm trying to use vba in MS Access to compare two fields to see if the
    second string can be found somewhere in the first.

    For example, I would like the statement to return true if:

    StrOne = 00035A,00035B,2 000,00103A
    StrTwo = 00035B

    Can anyone help?

    Thanks in advance,

    J
  • Jeff Pritchard

    #2
    Re: Compare two Strings in Access using VBA

    Try the InStr function.

    Jeff

    "Weiler" <weilerjunk@hot mail.com> wrote in message
    news:7833acfd.0 309062221.6cd73 92b@posting.goo gle.com...[color=blue]
    > I'm a relative newbie to VBA and I am STUMPED.
    >
    > I'm trying to use vba in MS Access to compare two fields to see if the
    > second string can be found somewhere in the first.
    >
    > For example, I would like the statement to return true if:
    >
    > StrOne = 00035A,00035B,2 000,00103A
    > StrTwo = 00035B
    >
    > Can anyone help?
    >
    > Thanks in advance,
    >
    > J[/color]


    Comment

    • Tim Marshall

      #3
      Re: Compare two Strings in Access using VBA

      Weiler wrote:[color=blue]
      >
      > For example, I would like the statement to return true if:
      >
      > StrOne = 00035A,00035B,2 000,00103A
      > StrTwo = 00035B[/color]

      Look up help on the instr function. For the above,

      InStr(1,strOne, strTwo) = 8

      If it's 0, strTwo isn't in there.

      --
      Tim - http://www.ucs.mun.ca/~tmarshal/
      ^o<
      /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
      /^^ "Want some?" - Ditto

      Comment

      • CDB

        #4
        Re: Compare two Strings in Access using VBA

        Look up Instr() function in VBA Help.

        Or, reconsider the data design - such repeating values should not be stored
        in one field in a table. They should be stored in eg 4 records. Then VBA is
        not needed - SQL will do the job.

        Clive


        "Weiler" <weilerjunk@hot mail.com> wrote in message
        news:7833acfd.0 309062221.6cd73 92b@posting.goo gle.com...[color=blue]
        > I'm a relative newbie to VBA and I am STUMPED.
        >
        > I'm trying to use vba in MS Access to compare two fields to see if the
        > second string can be found somewhere in the first.
        >
        > For example, I would like the statement to return true if:
        >
        > StrOne = 00035A,00035B,2 000,00103A
        > StrTwo = 00035B
        >
        > Can anyone help?
        >
        > Thanks in advance,
        >
        > J[/color]


        Comment

        Working...