Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run time error when selecting a name with an apostrophy in a combo box

Status
Not open for further replies.

9889

Programmer
Feb 28, 2003
15
GB
Hi

I've created a combo box to search on a form which works fine. However, some of the names in the drop down list have apostrophies ie O'Conner which when selected comes up with a run time error.

I don't know how to overcome this error and would be grateful for any help.

Many thanks.
 
Please, post the code raising the error !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi
Thank you for your reply. Here is code I'm using

Private Sub Combo15_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Name] = '" & Me![Combo15] & "'"
Me.Bookmark = rs.Bookmark
End Sub

It's the line:

rs.FindFirst "[Name] = '" & Me![Combo15] &"'"

which gives the error.

Many thanks.

 
How are ya 9889 . . .

Try this:
Code:
[blue]   Dim rs As Object, DQ As String

   DQ = """"
   Set rs = Me.Recordset.Clone
   rs.FindFirst "[Name] =" & DQ & Me![Combo15] & DQ
   Me.Bookmark = rs.Bookmark[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Use this:
Code:
rs.FindFirst "[Name]='" & Replace(Me![Combo15], "'", "''") & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm fine thanks.

I'll try it and let you know the results.

Many thanks for your help.

 
9889 . . .

There's an error in my code:
Code:
[blue]   Set rs = Me.Recordset.Clone
[purple]should be:[/purple]
   Set rs = Me.RecordsetClone[/blue]
Sorry about the mess! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thank you for all your help. That's brilliant.

Best Wishes
 
9889 . . .

Be sure to have a look at the links provided by PHV and I! [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top