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

Access Search Form

P: 3
I am trying to build a search form that will display the data if the data exist and if the disposal check box is checked. I would like for an error message to display if the data exist, but the disposal check box is unchecked. I also would like an error message to display if the data does not exist at all.

Here is the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub cmdSearch_Click()
  3.     Dim strSampleNumber As String
  4.     Dim strSearch As String
  5.  
  6. 'Check txtSearch for Null value or Nill Entry first.
  7.  
  8.     If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
  9.         MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
  10.         Me![txtSearch].SetFocus
  11.  
  12.     Exit Sub
  13. End If
  14. '---------------------------------------------------------------
  15.  
  16. 'Performs the search using value entered into txtSearch
  17. 'and evaluates this against values in strStudentID
  18.  
  19.     DoCmd.ShowAllRecords
  20.     DoCmd.GoToControl ("sampleno")
  21.     DoCmd.FindRecord Me!txtSearch
  22.  
  23.     sampleno.SetFocus
  24.     strSampleNumber = sampleno.Text
  25.     txtSearch.SetFocus
  26.     strSearch = txtSearch.Text
  27.  
  28. 'If matching record found sets focus in strStudentID and shows msgbox
  29. 'and clears search control
  30.  
  31.     If strSampleNumber = strSearch Then
  32.         MsgBox "Match Found For: " & strSearch, , "Congratulations!"
  33.         txtSearch.SetFocus
  34.         txtSearch = ""
  35.  
  36.     'If value not found sets focus back to txtSearch and shows msgbox
  37.         Else
  38.           MsgBox "Sample ID " & strSearch & " has not been disposed.", _
  39.             , "Invalid Sample ID!"
  40.             txtSearch.SetFocus
  41.             txtSearch = ""
  42.     End If
  43. End Sub
  44.  
Sep 17 '07 #1
Share this Question
Share on Google+
1 Reply


Scott Price
Expert 100+
P: 1,384
I am trying to build a search form that will display the data if the data exist and if the disposal check box is checked. I would like for an error message to display if the data exist, but the disposal check box is unchecked. I also would like an error message to display if the data does not exist at all.

Here is the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub cmdSearch_Click()
  3.     Dim strSampleNumber As String
  4.     Dim strSearch As String
  5.  
  6. 'Check txtSearch for Null value or Nill Entry first.
  7.  
  8.     If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
  9.         MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
  10.         Me![txtSearch].SetFocus
  11.  
  12.     Exit Sub
  13. End If
  14. '---------------------------------------------------------------
  15.  
  16. 'Performs the search using value entered into txtSearch
  17. 'and evaluates this against values in strStudentID
  18.  
  19.     DoCmd.ShowAllRecords
  20.     DoCmd.GoToControl ("sampleno")
  21.     DoCmd.FindRecord Me!txtSearch
  22.  
  23.     sampleno.SetFocus
  24.     strSampleNumber = sampleno.Text
  25.     txtSearch.SetFocus
  26.     strSearch = txtSearch.Text
  27.  
  28. 'If matching record found sets focus in strStudentID and shows msgbox
  29. 'and clears search control
  30.  
  31.     If strSampleNumber = strSearch Then
  32.         MsgBox "Match Found For: " & strSearch, , "Congratulations!"
  33.         txtSearch.SetFocus
  34.         txtSearch = ""
  35.  
  36.     'If value not found sets focus back to txtSearch and shows msgbox
  37.         Else
  38.           MsgBox "Sample ID " & strSearch & " has not been disposed.", _
  39.             , "Invalid Sample ID!"
  40.             txtSearch.SetFocus
  41.             txtSearch = ""
  42.     End If
  43. End Sub
  44.  
To check if the check box is unchecked :-)
Expand|Select|Wrap|Line Numbers
  1. If Me!DisposalCheckBox = 0 Then
...

On your second error message, it looks like you have code for that already? Where are you running into problems on that?

Regards,
Scott
Sep 19 '07 #2

Post your reply

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