D DentTec Registered User. Local time Yesterday, 23:26 Joined Apr 3, 2011 Messages 25 May 6, 2011 #1 My SQL statement was working fine except when the value of criteria has the aspostrophe in it. How do you handle this problem ? Thanks
My SQL statement was working fine except when the value of criteria has the aspostrophe in it. How do you handle this problem ? Thanks
J Jeanette Cunningham AWF VIP Local time Today, 16:26 Joined Aug 8, 2010 Messages 245 May 6, 2011 #2 Post the sql. Here is an explanation of how to handle apostrophes in sql. http://allenbrowne.com/casu-17.html
Post the sql. Here is an explanation of how to handle apostrophes in sql. http://allenbrowne.com/casu-17.html
D DentTec Registered User. Local time Yesterday, 23:26 Joined Apr 3, 2011 Messages 25 May 6, 2011 #3 Thanks for the link Jeanette, I'll check it out soon. Sorry I posted a wrong one. Here is the correct one Dim sql As String sql = "SELECT blah blah, [Outstanding Invoices].Client" sql = sql & " FROM [Outstanding Invoices]" sql = sql & " GROUP BY blah" sql = sql & " HAVING ((([Outstanding Invoices].Client) = '" & clientSelected & "'))" sql = sql & xyz;" Me.RecordSource = sql whereas clientSelected is a value selected from a list box in my form I got an erro when my Client is OTTO'S. Last edited: May 6, 2011
Thanks for the link Jeanette, I'll check it out soon. Sorry I posted a wrong one. Here is the correct one Dim sql As String sql = "SELECT blah blah, [Outstanding Invoices].Client" sql = sql & " FROM [Outstanding Invoices]" sql = sql & " GROUP BY blah" sql = sql & " HAVING ((([Outstanding Invoices].Client) = '" & clientSelected & "'))" sql = sql & xyz;" Me.RecordSource = sql whereas clientSelected is a value selected from a list box in my form I got an erro when my Client is OTTO'S.
G Galaxiom Super Moderator Staff member Local time Today, 16:26 Joined Jan 20, 2009 Messages 12,895 May 6, 2011 #4 It does depend on the circumstances bu double quotes and also cause grief. One way is to double up the single quotes. Code: Replace({expression},"'", "''") The same can be done with double quotes. The most reliable way is if the string can be taken directly from a control. This common usage will fail if an apostrophe is included Code: DMax("fieldname", "tablename", "stringfield='" & Me.somecontrol & "'") But the following will be fine for the same string because Access deals with the datatype automatically and does not require the string delimiters. Code: DMax("fieldname", "tablename", "stringfield=Forms!formname.somecontrol")
It does depend on the circumstances bu double quotes and also cause grief. One way is to double up the single quotes. Code: Replace({expression},"'", "''") The same can be done with double quotes. The most reliable way is if the string can be taken directly from a control. This common usage will fail if an apostrophe is included Code: DMax("fieldname", "tablename", "stringfield='" & Me.somecontrol & "'") But the following will be fine for the same string because Access deals with the datatype automatically and does not require the string delimiters. Code: DMax("fieldname", "tablename", "stringfield=Forms!formname.somecontrol")
G Galaxiom Super Moderator Staff member Local time Today, 16:26 Joined Jan 20, 2009 Messages 12,895 May 6, 2011 #5 [Outstanding Invoices].Client<>"OTTO'S" Click to expand... Access is expecting the second single quote to close what it interprets as open single quote. However you woudn't have a problem if you were to use [Outstanding Invoices].Client<>Forms!formname.controlname
[Outstanding Invoices].Client<>"OTTO'S" Click to expand... Access is expecting the second single quote to close what it interprets as open single quote. However you woudn't have a problem if you were to use [Outstanding Invoices].Client<>Forms!formname.controlname
D DentTec Registered User. Local time Yesterday, 23:26 Joined Apr 3, 2011 Messages 25 May 6, 2011 #6 GalaxiomAtHome: I just correct my code, I posted a wrong SQL earlier. I'll take a look at your suggestion tomorrow. Thanks
GalaxiomAtHome: I just correct my code, I posted a wrong SQL earlier. I'll take a look at your suggestion tomorrow. Thanks
J Jeanette Cunningham AWF VIP Local time Today, 16:26 Joined Aug 8, 2010 Messages 245 May 6, 2011 #7 Dim sql As String sql = "SELECT blah blah, [Outstanding Invoices].Client" sql = sql & " FROM [Outstanding Invoices]" sql = sql & " GROUP BY blah" sql = sql & " HAVING ((([Outstanding Invoices].Client) = """ & clientSelected & """))" sql = sql & xyz;"
Dim sql As String sql = "SELECT blah blah, [Outstanding Invoices].Client" sql = sql & " FROM [Outstanding Invoices]" sql = sql & " GROUP BY blah" sql = sql & " HAVING ((([Outstanding Invoices].Client) = """ & clientSelected & """))" sql = sql & xyz;"
D DentTec Registered User. Local time Yesterday, 23:26 Joined Apr 3, 2011 Messages 25 May 7, 2011 #8 Thanks Jeanette, it works great.