
Dim FindHistory() As String               'module level array to hold bookmarks

Sub cmndAndOr_Click ()
     If cmndAndOr.Caption = "OR" Then     'switch states
          cmndAndOr.Caption = "AND"       '(this caption is used to
     Else                                 ' build a SQL WHERE clause)
          cmndAndOr.Caption = "OR"
     End If
End Sub

Sub cmndClearHistory_Click ()
     listFindHistory.Clear                'clear out old history
     ReDim FindHistory(0)                 'clear out old bookmarks
     cmndGoto.Enabled = False             'disable goto bookmark
End Sub

Sub cmndClose_Click ()
     formFind.Hide                        'hide this form
     formMain.Show                        'make sure main form is current
End Sub

Sub cmndFind_Click (Index As Integer)
     'build SQL WHERE clause: FileName Like '*name*' AND/OR PathName Like '*path*'
     'this finds any embedded text, not just exact matches
     criteria$ = "FileName Like '*" & textFind(0).Text & "*' " & cmndAndOr.Caption
     criteria$ = criteria$ & " PathName Like '*" & textFind(1).Text & "*'"
     
     cmndFind(0).Enabled = True           'start by enabling all buttons
     cmndFind(1).Enabled = True
     Select Case Index
          Case 0 'Previous
               formMain!dataMain.Recordset.FindPrevious criteria$
               If formMain!dataMain.Recordset.NoMatch Then cmndFind(0).Enabled = False
          Case 1 'Next
               formMain!dataMain.Recordset.FindNext criteria$
               If formMain!dataMain.Recordset.NoMatch Then cmndFind(1).Enabled = False
          Case 2 'First
               formMain!dataMain.Recordset.FindFirst criteria$
               cmndFind(0).Enabled = False
          Case 3 'Last
               formMain!dataMain.Recordset.FindLast criteria$
               cmndFind(1).Enabled = False
     End Select
     If Not formMain!dataMain.Recordset.NoMatch Then  'if we found a record, then
          item$ = formMain!textPathName.Text & "\" & formMain!textFileName.Text
          listFindHistory.AddItem item$               'add it to the history
          If formMain!dataMain.Recordset.Bookmarkable Then
               ReDim Preserve FindHistory(listFindHistory.ListCount - 1)
               FindHistory(listFindHistory.ListCount - 1) = formMain!dataMain.Recordset.Bookmark
               cmndGoto.Enabled = True                 'enable Goto bookmark
          End If
     End If
End Sub

Sub cmndGoto_Click ()
     book = FindHistory(listFindHistory.ListIndex)     'extract bookmark
     formMain!dataMain.Recordset.Bookmark = book       'and go to it
     formMain!dataMain.UpdateControls                  'make sure display is current
End Sub

Sub Form_Load ()
     textFind(0).Text = ""                             'blank out beginning text
     textFind(1).Text = ""
End Sub

Sub listFindHistory_DblClick ()
     cmndGoto_Click                                    'goto bookmark
End Sub

Sub textFind_Change (Index As Integer)
     cmndFind(0).Enabled = False             'changed criteria; no more previous
     cmndFind(1).Enabled = False             'changed criteria; no more next
End Sub

Sub textFind_GotFocus (Index As Integer)
     textFind(Index).SelStart = 0            'start at the beginning of text
     textFind(Index).SelLength = 100         'select all text
End Sub

Sub textFind_LostFocus (Index As Integer)
     textFind(Index).SelLength = 0           'deselect all text
End Sub

