473,668 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with filtering results in a search form

266 Contributor
I created a search form that works well except when i am searching for a record that has multiple entries in the corresponding table. i would to filter the results so that they will display all the information associated with that record if there is more than one. here is my code that i am using. thanks for your help!


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.         Address.SetFocus
  31.  
  32.  
  33.     'If value not found sets focus back to txtSearch and shows msgbox
  34.         Else
  35.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
  36.             , "Invalid Search Criterion!"
  37.             txtsearch.SetFocus
  38.     End If
  39. End Sub
Oct 8 '08 #1
19 2670
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try replacing lines 18 thru 23 of your code with the following:

Expand|Select|Wrap|Line Numbers
  1.     Address.SetFocus 
  2.     strStudentRef = Address.Text 
  3.     txtsearch.SetFocus
  4.     DoCmd.RunCommand acCmdFilterBySelection
Oct 9 '08 #2
didacticone
266 Contributor
Try replacing lines 18 thru 23 of your code with the following:

Expand|Select|Wrap|Line Numbers
  1.     Address.SetFocus 
  2.     strStudentRef = Address.Text 
  3.     txtsearch.SetFocus
  4.     DoCmd.RunCommand acCmdFilterBySelection
i got an error "the command or action "filterbyselect ion" isnt available now"
here is what my code looks like... thanks for your help!

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.     Address.SetFocus
  19.     strStudentRef = Address.Text
  20.  
  21.     txtsearch.SetFocus
  22.     DoCmd.RunCommand acCmdFilterBySelection
  23.  
  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.         Address.SetFocus
  31.  
  32.  
  33.     'If value not found sets focus back to txtSearch and shows msgbox
  34.         Else
  35.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
  36.             , "Invalid Search Criterion!"
  37.             txtsearch.SetFocus
  38.     End If
  39. End Sub
Oct 9 '08 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
Sorry, move line 22 to be between lines 18 and 19.

" DoCmd.RunComman d acCmdFilterBySe lection" needs to have focus on the Address field.
Oct 9 '08 #4
didacticone
266 Contributor
Sorry, move line 22 to be between lines 18 and 19.

" DoCmd.RunComman d acCmdFilterBySe lection" needs to have focus on the Address field.
ok i did what you said, but when i search it comes up as having found no matches. here is my code... thanks again for your help

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.     Address.SetFocus
  19.     DoCmd.RunCommand acCmdFilterBySelection
  20.     strStudentRef = Address.Text
  21.  
  22.     txtsearch.SetFocus
  23.  
  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.         Address.SetFocus
  31.  
  32.  
  33.     'If value not found sets focus back to txtSearch and shows msgbox
  34.         Else
  35.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
  36.             , "Invalid Search Criterion!"
  37.             txtsearch.SetFocus
  38.     End If
  39. End Sub
Oct 9 '08 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
try this. If this does not work, I will have to give you another method because this method requires that the search value be in the address field, not your search box.

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.RunCommand acCmdFilterBySelection
  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.         Address.SetFocus 
  31.  
  32.  
  33.     'If value not found sets focus back to txtSearch and shows msgbox 
  34.         Else 
  35.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _ 
  36.             , "Invalid Search Criterion!" 
  37.             txtsearch.SetFocus 
  38.     End If 
  39. End Sub
Oct 9 '08 #6
didacticone
266 Contributor
try this. If this does not work, I will have to give you another method because this method requires that the search value be in the address field, not your search box.

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.RunCommand acCmdFilterBySelection
  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.         Address.SetFocus 
  31.  
  32.  
  33.     'If value not found sets focus back to txtSearch and shows msgbox 
  34.         Else 
  35.           MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _ 
  36.             , "Invalid Search Criterion!" 
  37.             txtsearch.SetFocus 
  38.     End If 
  39. End Sub
still no luck... so what do you think the next step would be?
Oct 9 '08 #7
puppydogbuddy
1,923 Recognized Expert Top Contributor
I just have to analyze alternative methods, and use one that would not require focus in the field to be searched [Address]....one that will do the search based on what is entered in the textbox. i will get back to you asap, no later than tomorrow.
Oct 9 '08 #8
didacticone
266 Contributor
I just have to analyze alternative methods, and use one that would not require focus in the field to be searched [Address]....one that will do the search based on what is entered in the textbox. i will get back to you asap, no later than tomorrow.
ok great! thanks again!
Oct 9 '08 #9
puppydogbuddy
1,923 Recognized Expert Top Contributor
I forgot to ask you whether you are using the single Form view or continuous form view. If you use the single form view and get several matches on your search, you are only going to be able to display the one at a time. There are loads of options to deal with this.

For example .....You can have 2 forms associated with the same table, one for single matches and another for multiple matches. With code, you can count the number of records returned and based on returns > 1, switch to a continuous form view.....blah, blah.

With the code changes included below, you will have the capability of getting partial matches...for example if you were to type 124 in the test box, you should get every address that has 124 embedded in it. Keep in mind that the code is untested and probably will have to be debugged. You need to substitute your actual table name or query name where I used an illustrative object name.

Let me know how it goes.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()  
  2.     Dim strStudentRef As String  
  3.     Dim strSearch As String  
  4.     Dim  strSql 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.     Exit Sub  
  12. End If  
  13. '---------------------------------------------------------------  
  14.  
  15. 'Performs the search using value entered into txtSearch  
  16. 'and evaluates this against values in Address  
  17.  
  18.     DoCmd.ShowAllRecords  
  19.     strSql  = "Select Address from [YourTable]  Where [Address] Like '" & "*" & Me!txtSearch.Value & "*" & "';"
  20.     DoCmd.RunSQL strSql
  21.  
  22.     Address.SetFocus  
  23.     strStudentRef = Address.Text  
  24.     txtsearch.SetFocus  
  25.     strSearch = txtsearch.Text  
  26.  
  27. 'If matching record found sets focus in Address and shows msgbox  
  28. 'and clears search control  
  29.  
  30.     If strStudentRef = strSearch Then  
  31.         Address.SetFocus  
  32.  
  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 9 '08 #10

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

Similar topics

9
4346
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
19
2035
by: Chantelle | last post by:
I've got this A2K DB that has a continuous form that lists Suppliers and their details. The form has a field for each supplier that holds several Keywords that reflect the suppliers products or services. I am new to writing VB but managed to create a command button that filters the form based on a keyword that I type into a text box . The code I have is :- Dim strFilter As String
2
3087
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement filtering facility for all the columns of the treestore/liststore model in order to allow the user an easy search method to find the desired information. The treestore is created with information related to cars, the columns are:
0
5558
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
9
3939
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 - I have read every post out there and spent hours trying to figure out the problem with no success whatsoever - I have constrained the problem to one form however, and I think it's hiding somewhere in my code associated with this form, which is...
3
1347
by: dillneus | last post by:
hello, I have some problem with search menu. first i will explain the structure of my search mennu and then the problems that appears... For creating my search menu i have used tips from that site: http://allenbrowne.com/ser-62.html So I have Criteria part in Form Header and Results in Detail. Criteria are devided into parts by using Tabs. So I have Region Tab, Information type Tab, Product Tab and Competitor Tab. All are normally...
4
2186
by: roryok | last post by:
Hi, (Access 2002 & Windows XP Pro) I have a Select query and one of the columns has the following criteria: (from SQL view) HAVING (((order.orderDate)>=!! And (order.orderDate)<=!!)); This works OK when I'm using the Date Filter form with two unbound boxes which ask for the start and end dates. The query dynaset appears correctly. I now want to introduce a form (lets call it Results) between the Date filter form (above) and the...
6
1989
by: topher83 | last post by:
Hi Im trying to create a form to search a hardware database for items, the form consists of two boxes, a dropdown box and a text box. The user needs to choose a field from the dropdown box and then enter the text the want to search for in the text box and the press search Its comming up results have been filtered however its not displaying them Can anyone see any problems with my code Thanks Private Sub cmdSearch_Click() If...
1
2466
by: oneski | last post by:
help --- 403 You don't have permission Im trying to get a basic search to work on my website, but i keep getting a forbidden error come up. Im using WAMP5 server on a vista machine. The error file from the apache side says: (20024)The given path misformatted or contained invalid characters: Cannot map POST /test/%3C?=$PHP_SELF?%3E HTTP/1.1 to file, referer: http://localhost/test/searchscript.php and this is the code im using. ...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.