Link to home
Start Free TrialLog in
Avatar of janp
janpFlag for United States of America

asked on

Open a recordset in VBA using SQL with LIKE

Hello,

This may have a very simple solution.

I'm trying to open a recordset using visual basic syntax (see code below). If I run the same SQL statement as a query (SELECT [tbl Segments].* FROM [tbl Segments] WHERE [tbl Segments].sSegment LIKE 'Step[_]*';), it runs just fine and records are returned. But when I use the same SQL syntax in a recordset.open statement, nothing is returned. I know it must be something with the LIKE statement because I can replace the LIKE statement with ='Step_01' and it runs fine.

Is there something about the LIKE statement when it is being used in SQL in visual basic code?

Thanks

sSQL = "SELECT [tbl Segments].* " & _
         "FROM [tbl Segments] " & _
         "WHERE [tbl Segments].sSegment LIKE 'Step[_]*';"
           
rs.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of janp

ASKER

Thanks for quick reply! Yes that seemed to do the trick. Like I said, simple solution. :-)