Question about search form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • didacticone
    Contributor
    • Oct 2008
    • 266

    #1

    Question about search form

    hi, i have made a search form but still need some help. The form works but is completley case and letter sensitive and would like it to be a little more forgiving. I will paste my code and hopefully someone can help me. thanks!
    Code:
    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 Address
            
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("Address")
        DoCmd.FindRecord Me!txtsearch
            
        Address.SetFocus
        strStudentRef = Address.Text
        txtsearch.SetFocus
        strSearch = txtsearch.Text
            
    'If matching record found sets focus in Address and shows msgbox
    'and clears search control
    
        If strStudentRef = strSearch Then
            MsgBox "Match Found For: " & strSearch, , "Congratulations!"
            Address.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
    Last edited by NeoPa; Oct 9 '08, 12:42 PM. Reason: Please use the [CODE] tags provided
  • Annalyzer
    New Member
    • Aug 2007
    • 122

    #2
    Try using "like" instead of "=" to compare the two strings.

    Comment

    • didacticone
      Contributor
      • Oct 2008
      • 266

      #3
      Originally posted by Annalyzer
      Try using "like" instead of "=" to compare the two strings.
      when i do, i get "compile error: expected: expression"

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Generally, in a case like this, use ToUpper() or ToLower() on both sides of the comparison to ignore case.
        Code:
        If strA = strB Then ...
        then becomes :
        Code:
        If ToLower(strA) = ToLower(strB) Then ...

        Comment

        Working...