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!

Lookup has problem with lastname's with an apostrophe 2

Status
Not open for further replies.

cimoli

Technical User
Jul 30, 2010
207
US
I have a customer name lookup field on my form.
It was created by the MS wizard. It works.
Except for any person with an apostrophe in their name like
O'Rorke or O'Malley. I get a debug error when I pick such a
lastname. Below is the present AfterUpdate code in the combo box.

Is there a way to fix this to allow an apostrophe last name??
thanks much. Cimoli.


Private Sub CboCusName_AfterUpdate()

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

Set rs = Me.Recordset.Clone
rs.FindFirst "[LastName] = '" & Me![cboCusName] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub
 
Code:
Private Sub CboCusName_AfterUpdate()
   
    ' Find the record that matches the control.
    Dim rs As Object

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

Duane
Hook'D on Access
MS Access MVP
 
How are ya cimoli . . .

Try this:
Code:
[blue]   Dim rs As DAO.Recordset, DQ As String, Cri As String
   
   DQ = """"
   Cri = "rs.FindFirst [LastName] = " & DQ & Me![cboCusName] & DQ
   
   Set rs = Me.Recordset.Clone
   rs.FindFirst Cri
   
   
   If Not rs.NoMatch Then
      Me.Bookmark = rs.Bookmark
   Else
      MsgBox "'" & [Lastname] & "' Not Found! ... or Doesn't Exist!"
   End If[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Duane - I just tried the last one. I get a debug error yellowed at:

rs.FindFirst Cri

Can you check? thanks as usual. Cimoli
 
Boy, I need new glasses. I got mixed up on the responses. It was Aceman's code that had the debug. Sorry. so I just tried Duane's. It works well. So if no objections, I will use Duane's. Thanks to both of you. Cimoli
 
cimoli . . .

So sorry. It should've been:
Code:
[blue]Cri = "[LastName] = " & DQ & Me![cboCusName] & DQ[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Another (safer) way:
Code:
rs.FindFirst "LastName='" & Replace(Me!cboCusName, "'", "''") & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top