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!

Data.Recordset.FindFirst 1

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I'm trying to find the first record in a database that matches a certain string so I did this:

Private Sub Find_Click()
DataCont.Recordset.FindFirst "'A Field' = 'Some Text'"
If DataCont.Recordset.NoMatch = True Then
MsgBox "No match found"
End If
End Sub

The field name is correct as is the name of the data control. The field must have a space in it (changing the field name in the database would be a massive task). It just says "No Match Found" every time I search. And the string is in the database! I'm stuck:(

Thanks

elziko
 
Perhaps your need a wildcard! ex: "ART*"
For best performance, the criteria should be in either the form "field = value" where field is an indexed field in the underlying base table, or "field LIKE prefix" where field is an indexed field in the underlying base table and prefix is a prefix search string (for example, "ART*").


In general, for equivalent types of searches, the Seek method provides better performance than the Find methods. This assumes that table-type Recordset objects alone can satisfy your needs

RayMan
 
DataCont.Recordset.FindFirst "'A Field' = 'Some Text'"

???

With

DataCont.Recordset.FindFirst "'A Field =' " & LTrim(text1) & "'"


Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
If the field name has a space in it you must enclose the field name in square brackets.

The reason you were getting no motach is that with the syntax in your expression you were comparing 2 literal strings (by enclosing the field name in single quotes).

Try this:

DataCont.Recordset.FindFirst "[A Field] = 'Some Text'"

Or, if you have the string in a variable:

DataCont.Recordset.FindFirst "[A Field]='" & sSearchString & "'"
Simon
 
Ah! Brackets as opposed to quotes. Perfect, thanks.

elziko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top