
WHERE CLAUSE IN SELECT STATEMENT
Quote:
> I have code that sets up a WHERE clause as:
> Criteria = "[DIN]= '" & DIN$ & "' AND [LASTNAME]='" &
> LAST$ & "'"
> strSQL = "SELECT * FROM [Inmates] WHERE " & Criteria
> Set rst = dbs.OpenRecordset(strSQL)
> The problem is that there are names like O'KELLY that come
> up and SQL gives an error because the WHERE clause gives:
> WHERE [LASTNAME]='O'KELLY'
> How can I set it up so names with apostrophes do not
> bomb? Thanks.
there's several way, I use this one:
Criteria = "[DIN]= """ & DIN$ & """ AND [LASTNAME]=""" & LAST$ & """"
strSQL = "SELECT * FROM [Inmates] WHERE " & Criteria
Set rst = dbs.OpenRecordset(strSQL)
or you could use
Criteria = "[DIN]= " & chr(34) & DIN$ & chr(34) & " AND [LASTNAME]=" &
chr(34) & LAST$ & chr(34)
strSQL = "SELECT * FROM [Inmates] WHERE " & Criteria
Set rst = dbs.OpenRecordset(strSQL)
--
Tony Oakley (Microsoft Access MVP)
GSXR1300R Hayabusa
300hr 240GB TiVo