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! - 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
-
Address.SetFocus
-
-
-
'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
19 2670
Try replacing lines 18 thru 23 of your code with the following: -
Address.SetFocus
-
strStudentRef = Address.Text
-
txtsearch.SetFocus
-
DoCmd.RunCommand acCmdFilterBySelection
Try replacing lines 18 thru 23 of your code with the following: -
Address.SetFocus
-
strStudentRef = Address.Text
-
txtsearch.SetFocus
-
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! - 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
-
Address.SetFocus
-
strStudentRef = Address.Text
-
-
txtsearch.SetFocus
-
DoCmd.RunCommand acCmdFilterBySelection
-
-
strSearch = txtsearch.Text
-
-
'If matching record found sets focus in Address and shows msgbox
-
'and clears search control
-
-
If strStudentRef = strSearch Then
-
Address.SetFocus
-
-
-
'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
Sorry, move line 22 to be between lines 18 and 19.
" DoCmd.RunComman d acCmdFilterBySe lection" needs to have focus on the Address field.
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 - 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
-
Address.SetFocus
-
DoCmd.RunCommand acCmdFilterBySelection
-
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
-
Address.SetFocus
-
-
-
'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
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. -
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.RunCommand acCmdFilterBySelection
-
-
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
-
Address.SetFocus
-
-
-
'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
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. -
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.RunCommand acCmdFilterBySelection
-
-
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
-
Address.SetFocus
-
-
-
'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
still no luck... so what do you think the next step would be?
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.
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!
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. -
Private Sub cmdSearch_Click()
-
Dim strStudentRef As String
-
Dim strSearch As String
-
Dim strSql 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
-
strSql = "Select Address from [YourTable] Where [Address] Like '" & "*" & Me!txtSearch.Value & "*" & "';"
-
DoCmd.RunSQL strSql
-
-
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
-
Address.SetFocus
-
-
-
'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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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:
|
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
|
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...
| |
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...
|
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...
|
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...
|
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.
...
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |