473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access Search Form

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
1 1488
Scott Price
1,384 Expert 1GB
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

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

Similar topics

3
by: TrvlOrm | last post by:
I am having great difficulty in these asp scripts, using VBscript and JavaScript. I have 4 files that all need to be linked together. The first file "Books.html" - needs to search for a Book...
1
by: Jack-of-all-traits | last post by:
This is a big problem and I really need help, no one seems to know how to solve this problem. I want to take the data from a record in a particular a field that contains the names of generic...
5
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Jan Szymczuk | last post by:
Thanks again guys, for your recent assistance. Now as you were so kind to assist the first time (the solution was so simple and elegant) I was wondering if you could assist with another couple of...
2
by: Homey! | last post by:
Hello all I am new to Access. I have imported data from an old FoxPro 2.x database. This is probably the most basic function but I cant get a search box to work. I need to search for company name...
1
by: TheDataGuy | last post by:
Using MS ACCESS 2002 Problem - I developed a form, and within that FORM, I added a SEARCH BUTTON, and then I created a SUB-FORM, so when an end user clicks on the FORM it will POP-UP the SUB-FORM,...
9
by: lightning | last post by:
Hi all, I'm not very conversant with the vocabulary of Access, so please ask for clarification if necessary... I am trying to build a search form that allows combinations of search terms. For...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.