thetambarineman
Technical User
Hello all,
the following is my code for searching through a database..
I realise that this is a bit of an over-kill for searching through databases - but its the way i learned way back in vb3-and old habits die hard!!!
Anyway-the problem is that it doesnt seem to be looping around again if a record is found
'this is called from the code..
'what it does is checks all of the string in a DB for your search string and matches it hopefully!!
'The only thing is that its only finding 1 record-then stopping despite there being loads of similiar records which match the search criteria!!!
Sub systemsearch(sysdata As Data, sysfield As String, syssearchdata As String, syssearchlist As ListBox)
recsfound = 0
sysdata.Recordset.MoveFirst
Do While sysdata.Recordset.EOF = False
startpos = 1
fieldlen = Len(sysdata.Recordset(sysfield))
stringlen = Len(syssearchdata)
Do Until startpos > (fieldlen - stringlen) + 1
matchstring = Mid$(sysdata.Recordset(sysfield), startpos, stringlen)
If UCase(matchstring) = UCase(syssearchdata) Then
syssearchlist.AddItem (sysdata.Recordset(sysfield))
recfound = MsgBox("Record located..", vbInformation + vbOKOnly, "Records located"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
continueflag = False
Do Until continueflag = True
DoEvents
Loop
End If
startpos = startpos + 1
Loop
If sysdata.Recordset.EOF = False Then sysdata.Recordset.MoveNext
Loop
If found = False Then
reply = MsgBox("No records found.. Please refine your search", vbInformation + vbOKOnly, "No records found"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
End If
End Sub
Thanks in advance!!
And excellent improvements to the site-it looks really well!
Paul
the following is my code for searching through a database..
I realise that this is a bit of an over-kill for searching through databases - but its the way i learned way back in vb3-and old habits die hard!!!
Anyway-the problem is that it doesnt seem to be looping around again if a record is found
'this is called from the code..
'what it does is checks all of the string in a DB for your search string and matches it hopefully!!
'The only thing is that its only finding 1 record-then stopping despite there being loads of similiar records which match the search criteria!!!
Sub systemsearch(sysdata As Data, sysfield As String, syssearchdata As String, syssearchlist As ListBox)
recsfound = 0
sysdata.Recordset.MoveFirst
Do While sysdata.Recordset.EOF = False
startpos = 1
fieldlen = Len(sysdata.Recordset(sysfield))
stringlen = Len(syssearchdata)
Do Until startpos > (fieldlen - stringlen) + 1
matchstring = Mid$(sysdata.Recordset(sysfield), startpos, stringlen)
If UCase(matchstring) = UCase(syssearchdata) Then
syssearchlist.AddItem (sysdata.Recordset(sysfield))
recfound = MsgBox("Record located..", vbInformation + vbOKOnly, "Records located"
continueflag = False
Do Until continueflag = True
DoEvents
Loop
End If
startpos = startpos + 1
Loop
If sysdata.Recordset.EOF = False Then sysdata.Recordset.MoveNext
Loop
If found = False Then
reply = MsgBox("No records found.. Please refine your search", vbInformation + vbOKOnly, "No records found"
End If
End Sub
Thanks in advance!!
And excellent improvements to the site-it looks really well!
Paul