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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box problem 1

Status
Not open for further replies.

ISTodd

Technical User
Mar 25, 2004
43
US
I have placed a combo box on a form that will "look up" and "retrieve" a record from a query. The problem I am having is that when I type a name with an aprostophe, I am recieving: Run-time error '3077':
syntax error (missing operator) in exopression.

When I click "DEBUG" I get this report:

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

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


Any ideas on how to de-bug this so I can retieve names with the (')?

Thanks for any help you can offer,
Todd
 
Try either:

[tt]rs.FindFirst "[expr1] = """ & Me![Combo415] & """"[/tt]

or

[tt]rs.FindFirst "[expr1] = '" & replace(Me![Combo415],"'","''") & "'"[/tt]

Roy-Vidar
 
What I do that makes things a little cleaner and easier to read is to set a global variable = " to be used anytime you need to search where there may be an apostrophe

Public Const strQuote As String = """"

then your line of code would be

rs.FindFirst "[Expr1]=" & strQuote & Me.Combo415 & strQuote

Hope this helps.

OnTheFly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top