Rick,
 
    If a text string containing single and/or double quotes in  various permutations and combinations is required to be appended to the target table by using the VALUES clause (within the Insert SQL), each original quote (that is required to appear undisturbed in the final result), has first to be replaced by double occurrence of the same, and this in turn has to be enclosed within double quotes. This can be implemented through suitable user defined function.
 
    If the situation permits use of a text box as source, the task can be drastically simplified by using SELECT (instead of VALUES)clause. Raw contents of source text box can be used straightaway, without needing any tedious conversion of text string. Either of the following two alternatives can be used.
        (a) If source text box has to be kept unbound, it's value is fed to the SQL through a user defined function.
        (b) If the source text box can be bound to a dedicated table (It could even be a table with single record), the SQL can be devised in a straightforward manner.
    
    All the alternatives outlined above, are covered (in the context of append as well as update queries) in my sample db named FixMixedQuotes at Rogers Access Library (other developers section). Link -
 
    The underlying approach could be adapted suitably for your specific needs.
 
Regards,
A.D.Tejpal
--------------
 
----- Original Message -----
From: allisonrja
Sent: Tuesday, September 06, 2005 06:49
Subject: [AccessDevelopers] how to handle quotes on insert

I have this SQL statement
strSQL = "Insert into tblTempArmBand " & _
 "(ArmBandSequence, ArmBandNumber, CallName, HandlerName, DogID) " & _
 "values (" & intLoop & ",""" & rst!ArmBandNumber & """,""" & _
 IIf(IsNull(rst!CallName), " ", rst!CallName) & _
 """,""" & rst!HandlerName & """," & rst!DogID & ")"

I just ran into a situation where CallName = "D".  Yes it has the
quotes in the name.  The SQL statement bombs because it looks like this...
Insert into tblTempArmBand (ArmBandSequence, ArmBandNumber, CallName,
HandlerName, DogID) values (110,"20134",""D"","Silvia King",355)

It blows because of the ""D""

What works better is
Insert into tblTempArmBand (ArmBandSequence, ArmBandNumber, CallName,
HandlerName, DogID) values (110,"20134",'"D"',"Silvia King",355)

But how do I code for single quotes?

Thanks,

Rick



Please zip all files prior to uploading to Files section.




YAHOO! GROUPS LINKS




Reply via email to