Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting a string with an apostrophe
Message
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00568577
Message ID:
00568587
Views:
18
This message has been marked as the solution to the initial question of the thread.
>I am doing an insert:
>
>sSql = "Insert " & _
> "Into GWC.Cert_Agnc_Hldr " & _
> "(agnc_num, hldr_name) " & _
> "Values('" & sAgncNum & "', '" & sDsplyName "')"
>
>The problem is that I ran across a value for sDsplyName that was: Mac's.
>when it runs into this particular value for name, it gives me an error because of the apostrophe. Is there any way to do this without removing the ' from Mac's?
>Thanks,
>Ryan Uhl

To what database are you inserting to? In SQL Server you can double up single quotes in SQL statements to get just one inserted, so you could probably check for the existence of them with Instr() and if there are then you can use Replace() to double them up before adding it to the sSql string like so:
If Instr(myValue, "'")<>0 Then
   myValue = Replace(myValue, "'", "''")
End If
sSql = .. etc.
If it isn't SQL Server then this might not work. HTH
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform