Eric Starkenburg
eric.starkenburg at home.nl
Fri Mar 7 17:09:15 CST 2008
Arthur, I just used the code underneith to test your theory.... The table used has just one field called test in table test. The form is called form1 and the textbox is called txtTest Sample text in textbox on a form: dit moe'st ook "maar" eens getest wor'dn Code used to save to table on a buttonpress: Dim db As DAO.Database Set db = CurrentDb Dim strtest As String strtest = Replace(txtTest, Chr(39), Chr(39) & Chr(39)) strtest = Replace(txtTest, Chr(34), Chr(34) & Chr(34)) db.Execute "insert into test (test) VALUES ('" & strtest & "')" Set db = Nothing Works like a charme without quotes in a sentence but with the sample text I get an error: Operator missing blablabla What did I do wrong? -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Friday, March 07, 2008 11:29 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] FW: CodeL If you do both Replace() calls, yes, and the count of occurrences is irrelevant since it replaces them all. Arthur On 3/7/08, Eric Starkenburg <eric.starkenburg at home.nl> wrote: > > Arthur, > > Does this work when both characters exist in one sentence? > Maybe the single quote once and two double quotes. > > > > Regards, > Eric > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller > Sent: Friday, March 07, 2008 11:07 PM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] FW: CodeL > > This is overkill, I think, Eric. You just have to know how to handle SQL > containing either single or double quotes or neither. It's quite > straightforward, really. You can eliminate all the hassle for any column > that might contain these values by doubling up on the single and double > quotes, which you can do in exactly one statement each: > > Replace( [columnName], Chr(39), (Chr(39) & Chr(39) ) > and similarly > Replace( [columnName], Chr(34), (Chr(34) & Chr(34) ) > > You can wrap both calls into a function if you wish. The code does nothing > on values that don't contain the offending characters. > > Having been bitten by surnames like O'Hara and embedded quotations, if I > suspect that this might ever occur, I just pre-empt it right from the > beginning. > > hth, > Arthur > -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com _____ avast! Antivirus <http://www.avast.com> : Uitgaande bericht is niet besmet. Virus Gegevensbestand (VPS): 080307-0, 07-03-2008 Getest op: 8-3-2008 0:09:15 avast! - auteursrecht (c) 1988-2008 ALWIL Software.