Apostrophe in entry in an input field

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

Guest

I have a name in a dropdown list that opens a data entry form for the person
with that name. When the name has an apostrophe in it, clicking on the name
results in an error message: when I click the debug button I get the
following code with this line (rs.FindFirst "[Expr1] = '" & Me![Combo128] &
"'") in yellow. How can I repair this code?


Option Compare Database
Private Sub Combo128_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Expr1] = '" & Me![Combo128] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Thanks
 
Here are two possibilities:

rs.FindFirst "[Expr1] = " & Chr$(34) & Me![Combo128] & Chr$(34)

or

rs.FindFirst "[Expr1] = '" & Replace(Me![Combo128], "'", "''") & "'"

exagerated for clarity,that Replace function is:

Replace(Me![Combo128], " ' ", " ' ' ")

You might also want to check my May, 2004 "Access Answers" column in
Pinnacle Publication's "Smart Access". You can download the column (and
sample database) for free at
http://www.accessmvp.com/DJSteele/SmartAccess.html
 
Back
Top