Open a recordset in VBA using SQL with LIKE

janp used Ask the Experts™

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 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?


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

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
you run that via ADODB?

then, you have to use % and not * as wild card..


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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial