Run-Time error 3077 with quotation marks

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

Guest

hello.

I am somewhat new to access and have been working on solving what appears to
be a coding problem. I have built a form that will copy information from a
list to a new record on the form. I was running into run-time errors with
apostrophe's and found the solution to the problem after reviewing posts on
this site. I am now running into run-time error with quotation marks. here
is the code:


Set rs = Me.Recordset.Clone
rs.FindFirst "[CDTitle] = " & Chr$(34) & Me![List10] & Chr$(34)
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

What else can I do to modify to the code so that it will allow use of both
quotation marks and apostrophe's? Is this possible?

Sincerely
 
You can use either single or double quotes as the delimiter. If your text
has both characters in it, you need to double which ever character you used
as the delimiter.

You can use the Replace function to do this:

strSQL = strSQL & "WHERE MyField = '" & Replace(MyText, "'", "''") & "'"

Exagerated for clarity, that's

strSQL = strSQL & "WHERE MyField = ' " & Replace(MyText, " ' ", " ' ' ") & "
' "

Alternately, you could use:

strSQL = strSQL & "WHERE MyField = " & Chr$(34) & Replace(MyText, Chr$(34) ,
Chr$(34) & Chr$(34)) & Chr$(34)
 
Back
Top