' in string of formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hiya

I have a problem with a recordset. I am trying to get the first record where a value matches the value of a string variable (cborecipient). This is the code

Dim dbs as Databas
Dim rst As Recordse
Set dbs = CurrentD
Set rst = dbs.OpenRecordset("Referring Trusts", dbOpenDynaset
rst.FindFirst ("[National Site/Trust Name] = '" & cborecipient & "'"

The problem is that sometimes the cborecipient string has an apostrophe in it (eg "St Mary's)
Do you know what I can do about this to stop an error occuring (Missing syntax) because of the extra apostrophe it will read? The table is nationally set, so I cannot simply remove the 's - I will need the look up to include it

Thanks for any help

T
 
Using the character code for double quotes - Chr(34) - will get around this

rst.FindFirst ("[National Site/Trust Name] = " & Chr(34) & cborecipient
& Chr(34) & ")"

hth,

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Tony T said:
Hiya,

I have a problem with a recordset. I am trying to get the first record
where a value matches the value of a string variable (cborecipient). This
is the code:
Dim dbs as Database
Dim rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Referring Trusts", dbOpenDynaset)
rst.FindFirst ("[National Site/Trust Name] = '" & cborecipient & "'")

The problem is that sometimes the cborecipient string has an apostrophe in it (eg "St Mary's).
Do you know what I can do about this to stop an error occuring (Missing
syntax) because of the extra apostrophe it will read? The table is
nationally set, so I cannot simply remove the 's - I will need the look up
to include it.
 
Back
Top