By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,490 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,490 IT Pros & Developers. It's quick & easy.

Question about search form

100+
P: 250
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!
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.     Dim strStudentRef As String
  3.     Dim strSearch As String
  4.  
  5. 'Check txtSearch for Null value or Nill Entry first.
  6.  
  7.     If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
  8.         MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
  9.         Me![txtsearch].SetFocus
  10.     Exit Sub
  11. End If
  12. '---------------------------------------------------------------
  13.  
  14. 'Performs the search using value entered into txtSearch
  15. 'and evaluates this against values in Address
  16.  
  17.     DoCmd.ShowAllRecords
  18.     DoCmd.GoToControl ("Address")
  19.     DoCmd.FindRecord Me!txtsearch
  20.  
  21.     Address.SetFocus
  22.     strStudentRef = Address.Text
  23.     txtsearch.SetFocus
  24.     strSearch = txtsearch.Text
  25.  
  26. 'If matching record found sets focus in Address and shows msgbox
  27. 'and clears search control
  28.  
  29.     If strStudentRef = strSearch Then
  30.         MsgBox "Match Found For: " & strSearch, , "Congratulations!"
  31.         Address.SetFocus
  32.         txtsearch = ""
  33.  
  34.     'If value not found sets focus back to txtSearch and shows msgbox
  35.         Else
  36.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
  37.             , "Invalid Search Criterion!"
  38.             txtsearch.SetFocus
  39.     End If
  40. End Sub
Oct 8 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 122
Try using "like" instead of "=" to compare the two strings.
Oct 8 '08 #2

100+
P: 250
Try using "like" instead of "=" to compare the two strings.
when i do, i get "compile error: expected: expression"
Oct 8 '08 #3

NeoPa
Expert Mod 15k+
P: 31,709
Generally, in a case like this, use ToUpper() or ToLower() on both sides of the comparison to ignore case.
Expand|Select|Wrap|Line Numbers
  1. If strA = strB Then ...
then becomes :
Expand|Select|Wrap|Line Numbers
  1. If ToLower(strA) = ToLower(strB) Then ...
Oct 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.