To: John Yingling
I used your code sample and modified it to fit my code as follows.
I still cannot stop the Find methode of the ADO Recordset once it is started
to the SQL server.
Is there a way of stopping it. Any help would be appreciated.
Also I have found that even though I reference an Previous connection
in my connection string I still get another connection showing on my SQL
2000 server any Ideas.
Morgan
Public mblnCancel As Boolean
Public mblnBusy As Boolean
Private Sub cmdFindCancel_Click()
If mblnBusy Then
mblnCancel = True
cmdFindCancel.Caption = "Find"
'mblnBusy = False
Exit Sub
End If
mblnBusy = True
'mblnCancel = False
cmdFindCancel.Caption = "Cancel"
' Must not reach here twice
Call Findtext(cboFindWhat.Text, cboLookIn.Text, cboMatch.Text, cboSearchDirection.Text)
mblnCancel = False
mblnBusy = False
cmdFindCancel.Caption = "Find"
End Sub
Function Findtext(findvalue As Variant, FindLookIn As String, _
FindMatch As String, FindDirection As String, Optional FindNextInt As Integer) As String
Dim adoQuoteRS As Recordset
Dim SearchDataType As Integer
Dim searcharray() As Variant
'create a recordset to search on
Dim strsql As String
Set adoQuoteRS = New Recordset
strsql = "SELECT tblQuotes.*, tblQuoteLog.*, tblProjects.* " & _
"FROM tblProjects " & _
"INNER JOIN tblQuotes ON tblProjects.ProjectsID = tblQuotes.ProjectID " & _
"INNER JOIN tblQuoteLog ON tblQuotes.QuoteID = tblQuoteLog.QuoteID"
adoQuoteRS.Open strsql, g_objConn, adOpenDynamic, adLockOptimistic
'Find out what field FINDLOOKIN is equal to and what datatype it is
If FindLookIn <> "Entire Database" Then
'find what datatype the field is
'there are many unused types listed here I just listed all of the possibilities
Select Case adoQuoteRS.Fields(FindLookIn).Type
Case Is = 0 'adEmpty=0
Case Is = 200 'adVarChar=200
searcharray() = FindSearch(adoQuoteRS, findvalue, FindLookIn, FindMatch, FindDirection)
Call QuoteLogViewSearch(searcharray)
End Select
Else
End If
Exit Function
Function FindSearch(searchRS As Recordset, findvalue As Variant, FindLookIn As String, _
FindMatch As String, FindDirection As String, Optional FindNextInt As Integer) As Variant
Dim searchfound(3) As Variant
'frmSearch.MousePointer = vbHourglass
Do While (frmSearch.mblnCancel = False)
DoEvents
Select Case FindMatch
Case Is = "Any Part Of Field"
If FindNextInt = 1 Then
With searchRS
Select Case FindDirection
Case Is = "All"
.Find FindLookIn & " like %" & findvalue & "%", 1
Case Is = "Up"
.Find FindLookIn & " like %" & findvalue & "%", 1, adSearchBackward
Case Is = "Down"
.Find FindLookIn & " like %" & findvalue & "%", 1, adSearchForward
End Select
'.Find FindLookIn & " like %" & findvalue & "%"
If .BOF Or .EOF Then
MsgBox "Matching Record not Found"
Else
searchfound(0) = searchRS.Fields("ProjectsID"

searchfound(1) = searchRS.Fields("QuoteID"

searchfound(2) = searchRS.Fields("QuoteNoRevision"

End If
End With
Else
With searchRS
Select Case FindDirection
Case Is = "All"
.Find FindLookIn & " like %" & findvalue & "%"
Case Is = "Up"
.Find FindLookIn & " like %" & findvalue & "%", , adSearchBackward
Case Is = "Down"
.Find FindLookIn & " like %" & findvalue & "%", , adSearchForward
End Select
'.Find FindLookIn & " like %" & findvalue & "%"
If .BOF Or .EOF Then
MsgBox "Matching Record not Found"
Else
searchfound(0) = searchRS.Fields("ProjectsID"

searchfound(1) = searchRS.Fields("QuoteID"

searchfound(2) = searchRS.Fields("QuoteNoRevision"

End If
End With
End If
End Select
frmSearch.mblnCancel = True
Loop
FindSearch = searchfound
searchRS.Close
end function