Search for partial strings in database

I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.

Example:
strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
when opened with a recordset
rsMember.Open strSQL, etc.
returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.

If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.

Thanks

Comments

  • : I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.
    :
    : Example:
    : strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
    : when opened with a recordset
    : rsMember.Open strSQL, etc.
    : returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.
    :
    : If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.

    In standard SQL, the LIKE wildcard is '%', not '*'.
  • : : I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.
    : :
    : : Example:
    : : strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
    : : when opened with a recordset
    : : rsMember.Open strSQL, etc.
    : : returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.
    : :
    : : If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.
    :
    : In standard SQL, the LIKE wildcard is '%', not '*'.
    :

    Thank you, the % sign worked. I used the * because that is the wildcard for Access. Didn't think to try the % sign.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories