check for special chars in textbox

if I use double "".. will it accept any parameter?

No.
First, there is no problem with special characters in general.

The only problem here is the situation when the character you use as delimiter occurs in the text itself.

Example:
Code:
...WHERE LastName = 'O'Brien';
The SQL parser thinks the ' in O'Brien ends the literal. The SQL as a whole is invalid then.

Solution: You double the ' inside your text values.
Example:
Code:
...WHERE LastName = 'O''Brien';
This works and is treated as one '. - For clarification, there are two ' inside the text not a double qoute (").

You can achieve this by replacing a single ' with two '
Code:
...WHERE LastName = '"  & Replace(strLastName,"'","''") & "';

If you use double quotes (") as delimiter, it is all the same. Then a single quote (') will do no harm then, but if a double quote happens to be inside the string, you need once more replace the one double quote (") with two double quotes ("").
 
No.
First, there is no problem with special characters in general.

The only problem here is the situation when the character you use as delimiter occurs in the text itself.

Example:
Code:
...WHERE LastName = 'O'Brien';
The SQL parser thinks the ' in O'Brien ends the literal. The SQL as a whole is invalid then.

Solution: You double the ' inside your text values.
Example:
Code:
...WHERE LastName = 'O''Brien';
This works and is treated as one '. - For clarification, there are two ' inside the text not a double qoute (").

You can achieve this by replacing a single ' with two '
Code:
...WHERE LastName = '"  & Replace(strLastName,"'","''") & "';
If you use double quotes (") as delimiter, it is all the same. Then a single quote (') will do no harm then, but if a double quote happens to be inside the string, you need once more replace the one double quote (") with two double quotes ("").

thanks ... but single '
is the single problematic char?
 
i have written a func (on sample code), fnAnySql, you dont need to add quote to the paramwter, just pass yiur control's value.

yes I saw it
thanks u so mach
ure wonderful
but i'm liitle afried use this function case I don't understand it
and i'm afried I will make my sofward more slowly
 
A single quote is the most common issue you will have
Either double it as Sonic8/Allen Browne described or use a function like arnelgp described.

You may also find this utility useful:
SQL to VBA and back again

However, other characters may be an issue depending on the context
For example, in a JSON array, additional colons ':' or full stops '.' can also cause issues
 

Users who are viewing this thread

Back
Top Bottom