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!

Searching... mistakes in my code??

Status
Not open for further replies.

thetambarineman

Technical User
Feb 29, 2000
63
GB
Ok apologies 4 this being a bit messy..
Im slap bang in the middle of this and i need to get it out quickly.. So any help is greatly appreciated..

Basically - what i want to do is search for a sub-string from within a string - all this comes from a database which is held on a seperate form..
This is what ive got so far-


reqemployer = txtsearchemp
recsfound = 0
frmemployer.dbemployer.Recordset.MoveFirst

Do While frmemployer.dbemployer.Recordset.EOF = False
startpos = 1
fieldlen = Len(frmemployer.dbemployer.Recordset("employer_name"))
stringlen = Len(reqemployer)
Do Until startpos > (fieldlen - stringlen) + 1
matchstring = Mid$(frmemployer.dbemployer.Recordset("employer_name"), startpos, stringlen)
If UCase(matchstring) = UCase(reqemployer) Then
recsfound = recsfound + 1
listempnamesearch.AddItem (frmemployer.dbemployer.Recordset("employer_name"))
MsgBox "Record found..."
continueflag = False
Do Until continueflag = True
DoEvents
Loop
End If
startpos = startpos + 1
Loop
If frmemployer.dbemployer.Recordset.EOF = False Then frmemployer.dbemployer.Recordset.MoveNext
Loop
end sub

this is only dev code- so thats why theres stubs- i.e. msgbox "Record found.." Later i hope to advance these a little.. Basically i want to know what im doing wrong with this code.. i cant insert an if in there anywhere to deal with not found records..

Thanks for your help..

Its all easy-im just making it hard 4 myself..

Thanks in advance..

Paul
 
I am not exactly sure what the problem is. Why don't you use the Instr() function?

It makes it much easier to read the code if you use TGML. Just make sure the Process TGML option is checked.

Code:
...put your code here

Then submit your post.

Probably didn't help too much, huh?
 
Why don't you either ;-)

1. Query the recordset on FieldName like '...' [ORDER BY...]

2. or Filter the recordset (see the filter property for either ADO or DAO) as in:
employer_name Like '*mystring*'

and be done with it ?

It will be so much faster and more elegant than by browsing ALL the records in the table... Your method will take forever as soon as you deal with more than a few records.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top