rs.FindFirst doesn't like apostrophe

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

Guest

Hello

I am using the code supplied by the combo box wizard to go to a specific
record based on the selection in the combo box. Code is as follows:

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone

'remove
rs.FindFirst "[Title] = ' " & Me![Combo66] & " ' "
Me.Bookmark = rs.Bookmark

Problem is that some of the values in the combo box contain apostrophes,
i.e. the "I'm" in "When I'm Sixty Four"
This seems to make the code crash every time, whereas other titles which
dont have apostrophes work fine.
Anyone know a way round this?
Thanks
 
I would suggest searching by an integer field (like an autonumber) set as
the primary key. Your combo box would be bound to this field. You can hide
this column and show only the text column(s) you want your user to see. So,
if your record has [RecordID]=1234 and [Title]="When I'm Sixty Four", your
combo box would be bound to [RecordID], and the column widths would be set
to 0",1" so it hides the RecordID and shows the Title. The search code
would then be:
rs.FindFirst "[RecordID] = " & Me![Combo66]
thus doing away with any problems associated with searching a text field.
 
Back
Top