Seaching using text box entry - Based on Student Search Database.

To perform the search you will need to enter a value (search based on student number) into the search box.

The code below is attached to cmdSearch button.  This code checks for a value (if none or no match then returns one msg and
set's focus to the search field.

If value found returns record and gives message and clears search box.

To try this example:

1. First click the command button on the form(without typing any value in) and you will be told to enter a value.

2. Next try entering a value of xxxxxx.  The message will advise that no student found with this value.

3. Finally type in DD27676.  This will return a match and take you to the record.

'--------------------------------------------------------------
'Graham Thorpe 25-01-02
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
    Dim strStudentRef As String
    Dim strSearch As String
    
'Check txtSearch for Null value or Nill Entry first.

If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
        
        'Performs the search using value entered into txtSearch
        'and evaluates this against values in strStudentID
        
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("strStudentID")
        DoCmd.FindRecord Me!txtSearch
        
        strStudentID.SetFocus
        strStudentRef = strStudentID.Text
        txtSearch.SetFocus
        strSearch = txtSearch.Text
    
        'If matching record found sets focus in strStudentID and shows msgbox
        'and clears search control

    If strStudentRef = strSearch Then
        MsgBox "Match Found For: " & strSearch, , "Congratulations!"
        strStudentID.SetFocus
        txtSearch = ""
        
    'If value not found sets focus back to txtSearch and shows msgbox
        Else
            MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", , "Invalid Search Criterion!"
            txtSearch.SetFocus
    End If
End Sub

-------------------------------------------------------------------




