Log in

View Full Version : [SOLVED:] Wrap single quotes around array values



ldoodle
01-07-2015, 08:40 AM
Hey,

I'm passing user input (InputBox) to a SQL query:



dim array as variant
array = split(userinput, ";")

select ...
from...
where x in ( join(array, ",") )

The problem is the values are strings, so I need to wrap single quotes around each of the values in array.

Can't quite figure this one out! I've tried looping through array, writing out to newarray, but my recordset reports subscript out of range when I do this. Removing the single quotes fixes it:



dim newarray as variant
for i = 0 to ubound(array)
newarray(i) = "'" & array(i) & "'"
next i




Thanks

ldoodle
01-07-2015, 09:10 AM
Ah! If I do:


newarray(i) = "'" & Trim(array(i)) & "'"

it works. Not sure why as I'm not putting spaces in anywhere.

EDIT: It's the space after the semi-colon in the user input.

Sorted!

SamT
01-07-2015, 11:30 AM
:thumb

ashleyrobbin
11-15-2015, 05:32 AM
great!