I need your help to match my fallacy (or just stupidity) by creating a simple SQL Query string in Excel VBA. Connection 3 is a Microsoft SQL database on a separate server. If I use the operator "=" the code work, when using "LIKE" instead runtime error 1004 occur...
This one works fine
With ActiveWorkbook.Connections(3)
.OLEDBConnection.CommandType = xlCmdSql
.OLEDBConnection.CommandText = "SELECT * FROM testSystems WHERE **partGroup='CLV'**"
.Refresh
Debug.Print .OLEDBConnection.CommandText
End With
This one exceeds in runtime error
With ActiveWorkbook.Connections(3)
.OLEDBConnection.CommandType = xlCmdSql
.OLEDBConnection.CommandText = "SELECT * FROM testSystems WHERE **partGroup LIKE 'CLV%'**"
.Refresh
Debug.Print .OLEDBConnection.CommandText
End With
I expecting that the LIKE statement works also in this case...