vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I'm sure this is a real simple one , whats the best trick when your select conditions have a ' in the value "WHERE (People.FullName = 'Example O'Toole' )" ? Chris Example strSQLPeople = "SELECT People.FullName " strSQLPeople = strSQLPeople & "FROM People " strSQLPeople = strSQLPeople & "WHERE (People.FullName = '" & Me.ComboFullName.Value & "' ) " strSQLPeople = strSQLPeople & "GROUP BY People.FullName " Set rstPeople = New ADODB.Recordset rstPeople.CursorType = adOpenStatic rstPeople.CursorLocation = adUseClient Debug.Print strSQLPeople ' strSQLPeople example ' SELECT People.FullName FROM People WHERE (People.FullName = 'Example O'Toole' ) GROUP BY People.FullName rstPeople.Open strSQLPeople , CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText |
| |||
| You could use the REPLACE function: spaces (in both lines of added for clarity) strName = REPLACE(strName, " ' ", " ' ' ") .... "WHERE (People.FullName = ' " & strName " ' )" should do it. Steve "Chris Joyce" <nntp(remove)@chrisjoyce.id.au> wrote in message news:ukxJHf1WEHA.3200@TK2MSFTNGP09.phx.gbl... > I'm sure this is a real simple one , > > whats the best trick when your select conditions have a ' in the value > "WHERE (People.FullName = 'Example O'Toole' )" ? > > Chris > > > Example > > strSQLPeople = "SELECT People.FullName " > strSQLPeople = strSQLPeople & "FROM People " > strSQLPeople = strSQLPeople & "WHERE (People.FullName = '" & > Me.ComboFullName.Value & "' ) " > strSQLPeople = strSQLPeople & "GROUP BY People.FullName " > > Set rstPeople = New ADODB.Recordset > rstPeople.CursorType = adOpenStatic > rstPeople.CursorLocation = adUseClient > > > Debug.Print strSQLPeople > > ' strSQLPeople example > ' SELECT People.FullName FROM People WHERE (People.FullName = 'Example > O'Toole' ) GROUP BY People.FullName > > rstPeople.Open strSQLPeople , CurrentProject.Connection, adOpenKeyset, > adLockOptimistic, adCmdText > > |
| ||||
| This is what parameters are for. Any reason you can't use parameters in this case? Brannon Steve Thompson wrote: > You could use the REPLACE function: spaces (in both lines of added for > clarity) > > strName = REPLACE(strName, " ' ", " ' ' ") > > ... > "WHERE (People.FullName = ' " & strName " ' )" > > should do it. > > Steve > "Chris Joyce" <nntp(remove)@chrisjoyce.id.au> wrote in message > news:ukxJHf1WEHA.3200@TK2MSFTNGP09.phx.gbl... > >>I'm sure this is a real simple one , >> >>whats the best trick when your select conditions have a ' in the value >>"WHERE (People.FullName = 'Example O'Toole' )" ? >> >>Chris >> >> >>Example >> >> strSQLPeople = "SELECT People.FullName " >> strSQLPeople = strSQLPeople & "FROM People " >> strSQLPeople = strSQLPeople & "WHERE (People.FullName = '" & >>Me.ComboFullName.Value & "' ) " >> strSQLPeople = strSQLPeople & "GROUP BY People.FullName " >> >>Set rstPeople = New ADODB.Recordset >>rstPeople.CursorType = adOpenStatic >>rstPeople.CursorLocation = adUseClient >> >> >>Debug.Print strSQLPeople >> >>' strSQLPeople example >>' SELECT People.FullName FROM People WHERE (People.FullName = 'Example >>O'Toole' ) GROUP BY People.FullName >> >>rstPeople.Open strSQLPeople , CurrentProject.Connection, adOpenKeyset, >>adLockOptimistic, adCmdText >> >> > > > |
| Thread Tools | |
| Display Modes | |
|
|