String problem

R

Rodtnick

I got some code from srfreeman that would check the title of the new
record I'm entering to see if that record has already been entered. I
works fine unless I have a word that has an apostrophe in it, like
What's. It seems that the apostrophe conflicts with a line in the code:
stLinkCriteria = "[SeriesTitle]=" & "'" & SID & "'". Here's my full
code:

Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.txtSeriesTitle.Value
stLinkCriteria = "[SeriesTitle]=" & "'" & SID & "'"

How can I work around this?

Bruce Rodtnick
 
D

Dirk Goldgar

Rodtnick said:
I got some code from srfreeman that would check the title of the new
record I'm entering to see if that record has already been entered. I
works fine unless I have a word that has an apostrophe in it, like
What's. It seems that the apostrophe conflicts with a line in the
code: stLinkCriteria = "[SeriesTitle]=" & "'" & SID & "'". Here's my
full code:

Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.txtSeriesTitle.Value
stLinkCriteria = "[SeriesTitle]=" & "'" & SID & "'"

How can I work around this?

Bruce Rodtnick

Try this.

Const strQ = """"

stLinkCriteria = _
"[SeriesTitle]=" & strQ & _
Replace(SID, strQ, strQ & strQ) & _
strQ

Instead of using the single-quote/apostrophe (') to delimit your search
text, it uses a double-quote ("). And just in case there's a
double-quote inside the text -- which would mess things up -- it
replaces any such embedded double-quote with a pair of them, which will
be interpreted inside the string literal as just one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top