0

I'm using Replace function in SQL query, it is working in access sql query design mode but not working in access VBA. Throwing expected end of statement. I tried all the ways but not working. CM column has a string like this ;#WR_1;#WR_2;#WR_3;#WR_4;# and I'm trying to get value WR_2 where ever the string occurs in CM column

strSQL = "SELECT * FROM WT_table " & _
"WHERE [CM] IS NOT NULL " & _
"AND (';' & Replace([CM], '#', "") & ';') Like '*;WR_2;*'; ;"

1 Answer 1

1

Just remove the second semi-colon (;) from the end of the last line - you have two of them, making it appear that there are multiple statements to be executed.

"AND (';' & Replace([CM], '#', "") & ';') Like '*;WR_2;*';"

In addition, as pointed out by simoco, you have a pair of double-quotes in your Replace function. I'm not certain whether you mean to have two single-quotes or not, but this would be the right code to use in that case:

"AND (';' & Replace([CM], '#', '') & ';') Like '*;WR_2;*';"
Sign up to request clarification or add additional context in comments.

2 Comments

No luck. saying syntax error in string in query expression [CM] IS NOT NULL AND (';' & Replace([CM], '#', "") & ';') Like ';WR_2;'
I have just made an edit following another user comment to also reflect that you have two double-quotes in the last line, where you possibly mean two single-quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.