Apostrophe Error in LastName

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

Guest

Hi all,
I have a form with a search box that lists the full names of Employees: -

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

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

This works fine when choosing 'Joe Bloggs' as it correctly returns the
correct record. However, I noticed this morning that choosing 'Geoffrey
O'Brien' results in the following error: -

Run-time error '3077':
Syntax error (missing operator) in expression.

It must be picking up on the ' (apostrophe) in his last name! Is there a way
around this?

Thanks.
 
BetaMike wrote in message
Hi all,
I have a form with a search box that lists the full names of
Employees: -

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

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

This works fine when choosing 'Joe Bloggs' as it correctly returns
the correct record. However, I noticed this morning that choosing
'Geoffrey O'Brien' results in the following error: -

Run-time error '3077':
Syntax error (missing operator) in expression.

It must be picking up on the ' (apostrophe) in his last name! Is
there a way around this?

Thanks.

Wouldn't you be using a primary key field for such in stead of a long
string?

Anyway, here's a couple of ways of dealing with apostrophes

rs.FindFirst "[FullName]= '" & replace(Me![Combo66], "'", "''") & "'"

- replace any single occurance of it, with two

rs.FindFirst "[FullName]= """ & Me![Combo66] & """"

- doublequoting
 
If you don't understand the double-quotes that Roy suggested, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

RoyVidar said:
BetaMike wrote in message
Hi all,
I have a form with a search box that lists the full names of Employees: -

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

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

This works fine when choosing 'Joe Bloggs' as it correctly returns the
correct record. However, I noticed this morning that choosing 'Geoffrey
O'Brien' results in the following error: -

Run-time error '3077':
Syntax error (missing operator) in expression.

It must be picking up on the ' (apostrophe) in his last name! Is there a
way around this?

Thanks.

Wouldn't you be using a primary key field for such in stead of a long
string?

Anyway, here's a couple of ways of dealing with apostrophes

rs.FindFirst "[FullName]= '" & replace(Me![Combo66], "'", "''") & "'"

- replace any single occurance of it, with two

rs.FindFirst "[FullName]= """ & Me![Combo66] & """"

- doublequoting
 
Roy, thanks for the fix and also thanks to Allen for the explanation :)


RoyVidar said:
BetaMike wrote in message
Hi all,
I have a form with a search box that lists the full names of
Employees: -

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

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

This works fine when choosing 'Joe Bloggs' as it correctly returns
the correct record. However, I noticed this morning that choosing
'Geoffrey O'Brien' results in the following error: -

Run-time error '3077':
Syntax error (missing operator) in expression.

It must be picking up on the ' (apostrophe) in his last name! Is
there a way around this?

Thanks.

Wouldn't you be using a primary key field for such in stead of a long
string?

Anyway, here's a couple of ways of dealing with apostrophes

rs.FindFirst "[FullName]= '" & replace(Me![Combo66], "'", "''") & "'"

- replace any single occurance of it, with two

rs.FindFirst "[FullName]= """ & Me![Combo66] & """"

- doublequoting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top