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

Findfirst fails because data item has double quotes inside quotes..... 2

Status
Not open for further replies.

Pack10

Programmer
Feb 3, 2010
495
0
0
US
I am running a find first and getting a syntax error on one of the values in the table.
The data item is Gilette "Boston" Stadium. For background, it dealing with expense items, so someone took someone to a game
and entered in Gilette "Boston" Stadium... but my findfirst is failing because of the double quotes.....how would I code this?

thanks
 

Background
------------
They have an expenses table and a table containing searching terms. I loop thru the expenses table looking for a matching search term
My code is failing on items that have double quotes inside the value ie...Gillette "Boston" Stadium


Do While st = 1

' store search value to be used in criteria
If Not IsNull(rsExpenses!Purpose) Then
strPurpose = rsExpenses!Purpose
End If

' ensure we are at the beginning of the table
rsSearchTerms.MoveFirst
rsSearchTerms.FindFirst "Term Like """ & strPurpose & "*"""

If rsSearchTerms.NoMatch = False Then
' I want to write that record to a table for reporting
Endif
 
Code:
Private Sub Command16_Click()
  Dim rs As DAO.Recordset
  Set rs = Me.Recordset
  Dim str As String
  str = Me.Text14
  str = Replace(str, """", """""")
  str = Replace(str, "'", "''")
  rs.FindFirst "txtFld = '" & str & "'"
End Sub

I have in my table
Smith
"Smith"
'Smith'

finds all of them
 
Code:
Replace this:
rsSearchTerms.FindFirst "Term Like """ & strPurpose & "*"""
with this:
rsSearchTerms.FindFirst "Term Like '" & Replace(strPurpose, "'", "''") & "*'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Brilliant... Worked great thank you
 
Hi

I did it from my phone last night and just checked it. It didnt save. So I re-entered it.
This site is the best, and I will again send a small token of my appreciation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top