PDA

View Full Version : Solved: FindFirst Criteria w Quotes



Imdabaum
02-16-2007, 12:27 PM
With Me.RecordsetClone
.FindFirst "PropertyID= " & Me.lstDates.Column(0) & _
" AND NoteDate= #" & Me.lstDates.Column(1) & "#" & _
" AND Memo = '" & Me.lstDates.Column(2) & "'"
If .NoMatch Then
MsgBox "The Record you selected was not found.", vbInformation, "Not Found"
Else
Me.Bookmark = .Bookmark
End If
End With


I used this code to select a record from a listbox, but it occurred to me that this would not allow for apostraphes. In order to take apostrophes into account I created 2 variables as suggested in the Help File.


Dim Q As String
Dim QQ As String
Q = Chr(34)
QQ = Q & Q
With Me.RecordsetClone
.FindFirst "PropertyID= " & Me.lstDates.Column(0) & _
" AND NoteDate= #" & Me.lstDates.Column(1) & "#" & _
" AND Memo = " & Q & Replace(Me.lstDates.Column(2), Q, QQ) & Q & _
" AND entryDate = " & Q & Me.lstDates.Column(4) & Q
If .NoMatch Then
MsgBox "The Record you selected was not found.", vbInformation, "Not Found"
Else
Me.Bookmark = .Bookmark
End If
End With


Now it properly selects all items from the listbox that have an apostrophe or double quotes, but it fails to find some of the items that don't have the apostophes. Can anyone help me find out why all items cannot be found?

OBP
02-17-2007, 11:03 AM
First of all, did the previous version find the records that the new version doesn't find?
Second, can you give some examples of the data that it didn't find?

Imdabaum
02-26-2007, 12:41 PM
The first version didn't work either, it only appeared to work, because whoever wrote it put On Error Resume Next so it just found (I'm assuming) the first record in the CloneSet. I figured the code was the problem but was checked out the table def. There were no record ids, everything was being searched by the property id and doing a text match on the note itself.I recovered the design master and created a record id field and made it autonumber. Then simply selected the recordID from the listbox.column(0).no need to match text or anything and it works like a charm so far.