473,748 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple search in a single field

3 New Member
Hi all
I have a table in MS access containing drugs and another table containing drugs composition (component).
in my search form, i have the possibility to search, in my drug database, for a particular component.
How can I sear for 2 different components in a single drug without creating a seconf field for component search,
because sometimes i will need to search for a drug containing 3 or more components.
My solution was to convert my actual search field for component to a search with checkboxes where i can choose the different components i am looking for

anyone can help?
Jul 2 '16 #1
7 1129
ADezii
8,834 Recognized Expert Expert
  1. I do have a strictly code-based solution whereas you can search for as many Components within a Drug as you like. All the Components to search for can be listed in a single Text Box in a Delimited Format such as listed below. You can also specify your Delimiter between Components:
    Expand|Select|Wrap|Line Numbers
    1. Component A,Component G,Component Q,Component Z
  2. This approach has a very strict syntax requirement and the Components to search for much match exactly with those in a Components Table should they exist.
  3. A SQL-based approach would be much better should one exist, so I'll simply wait and see what suggestions are offered prior to posting mine.
Jul 2 '16 #2
PhilOfWalton
1,430 Recognized Expert Top Contributor
I think this might be of help



Under Available Services there are 2 columns, left hand one is the definition and right hand one is the description.
At the bottom is a label saying "Enter a few letters of the service required (use a tilde ~ to separate words)"
To the right of that I have typed ca~cre.

This will search in both the definition and the description for words containing the letters "ca" or "cre"
Very flexible, very fast.

Phil
Jul 2 '16 #3
SusanSerbey
3 New Member
Can't wait ADezii, we tried a lot of solutions, but the result of the search was always wrong
I will wait yours
Jul 3 '16 #4
SusanSerbey
3 New Member
Thank you Phil,
we will try it early tomorow morning and be back to you
Jul 3 '16 #5
ADezii
8,834 Recognized Expert Expert
  1. I'm assuming that there can be literally thousands or tens-of-thousands of Drugs and their associated Components. For this reason, I decided not to go the List Box approach where you can selectively choose any number of Components among the thousands. If I am incorrect the Logic can easily be modified to incorporate a Multi-Select List Box or similar functionality whereas you can choose any number of Components among the thousands to test for.
  2. For the sake of simplicity I have created a simple One ==> MANY Relationship between Drugs and their Components but in reality this is not true. Since a single Drug can contain many Components, and a single Component can be contained in many Drugs, a MANY to MANY Relationship actually exists between the two. Again, this can be modified later on.
  3. I went with your original idea of listing one or more Components in a single Text Box on a Form then querying to see which Drugs, if any, contain ALL of the Components. I listed the Components in a Delimited Format using a ',' as the Default, such as:
    Expand|Select|Wrap|Line Numbers
    1. Component A,Component B,Component C, etc...
  4. You can change the Delimiter if you like by simply changing it in the Constant
    Expand|Select|Wrap|Line Numbers
    1. conDELIMITER
  5. I will not bore you with the details and Logic, simply download the Attached Demo. It should be self explanatory, but if you have any additional questions or comments, we are here to assist you.
  6. P.S. - All the Code exists in a simple Event Procedure for the sake of simplicity.
Attached Files
File Type: zip Demo.zip (83.5 KB, 61 views)
Jul 3 '16 #6
PhilOfWalton
1,430 Recognized Expert Top Contributor
Assuming you have a form with 2 columns one called drugs and one component, add a textbox "TxtFilter" in the footer, as per my image.

Try the following code
Expand|Select|Wrap|Line Numbers
  1. Sub FilterForm()
  2.  
  3.     Dim Fltr As String
  4.  
  5.     If SelectMediaType > 0 Then                         ' Media Type not all
  6.         Fltr = "MediaTypeID = " & SelectMediaType
  7.     End If
  8.  
  9.     ' If we return no records, tempotarily remove the filter
  10.     If Me.RecordsetClone.RecordCount = 0 Then
  11.         Me.FilterOn = False
  12.     End If
  13.  
  14.     TxtFilter.SetFocus
  15.  
  16.     If Left(TxtFilter.Text, 1) = "~" Then                ' Don't allow a tilde as first letter
  17.         TxtFilter.Text = ""
  18.     End If
  19.  
  20.     Fltr = "(Drugs Like '*" & Replace(Me.TxtFilter.Text, "'", "''") & "*'"
  21.     Fltr = Replace(Fltr, "~", "*' OR Drugs Like '*")
  22.     Fltr = Fltr & " OR Component Like '*" & Replace(Me.TxtFilter.Text, "'", "''") & "*'"
  23.     Fltr = Replace(Fltr, "~", "*' OR Component Like '*")
  24.     Fltr = Fltr & ")"
  25.  
  26.     Me.Form.Filter = Fltr
  27.     Me.FilterOn = True
  28.  
  29.  
  30.     Me.TxtFilter.SetFocus
  31.  
  32.     ' Move the cursor to the end of the input text box.
  33.     If Me.RecordsetClone.RecordCount = 0 Then
  34.         Exit Sub
  35.     End If
  36.  
  37.     Me.TxtFilter.SelStart = Len(Me.TxtFilter.Text)
  38.  
  39. End Sub
  40.  
Phil
Jul 4 '16 #7
NeoPa
32,570 Recognized Expert Moderator MVP
As I assume each drug can have multiple components and each component can be used in multiple drugs there will no doubt be a cross-referencing table that lists the connections between drugs and components. I don't know what your table's called so I'll simply call it [DrugComponent] for now and we may change it later when we get more information from you.

If we're interested in filtering directly then we need a set of data that includes both the drug and a list of the components. This is not straightforward and cannot be done leaving the resulting data editable. Nevertheless, Combining Rows-Opposite of Union gives a way it can be done.

With a form or report built on this data, which has a single record per drug and a field we'll call [ComponentList] for now, we can filter that data based on a filter string taken from a TextBox on the same or another form. We'll call that [txtFilter] for now. The AfterUpdate event procedure of the TextBox (I'll assume this is in the header of the same form used for showing this list of drugs in the Detail section for now.) can then be written to build a filter string that will allow each matching drug record to show.
Expand|Select|Wrap|Line Numbers
  1. Private txtFilter_AfterUpdate()
  2.     Dim strWhere As String, strSep As String
  3.     Dim astrComponent() As String
  4.     Dim varComponent As Variant
  5.  
  6.     strSep = ","
  7.     With Me
  8.         astrComponent = Split(.txtFilter, strSep)
  9.         For Each varComponent In astrComponent
  10.             strWhere = strWhere _
  11.                      & " OR ([ComponentList] Like '*" & varComponent & "*')"
  12.         Next varComponent
  13.         strwhere = Mid(strWhere, 5)
  14.         If strWhere <> .Filter Then .Filter = strWhere
  15.         .FilterOn = (.Filter > "")
  16.     End With
  17. End Sub
Jul 4 '16 #8

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

Similar topics

2
1568
by: Vishy | last post by:
Hi One of the less documented features of xpath is how to run multiple search on nodes or attributes e.g <Book name="Harry Potter" price="10GBP"/> <Book name="Harry Potter" price="5USD"/> now if you want one of them following is xpath query ..//Book
2
6582
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie. "Heart Disease,Hyper Tyroid,Cancer" etc. I would like to search via combo box for any one or more than one value in this field, ie-what patients have Heart Disease or Cancer by selecting these disorders off the combo box list. Any help would be...
1
8170
by: Casey | last post by:
Hi, How would one allow for possible multiple search criteria using FREETEXTTABLE. For example, my table "listings" has a full-text search catalog, and I may want to: SELECT * FROM listings WHERE name LIKE @name AND city LIKE @city I've got it working to select only by name: SELECT listing_id, RANK, name, address, city, zip, heading, phone FROM listings a,
2
10026
by: mukeshsrivastav | last post by:
dear sir, i m design a contact mgmt interface in vb using access . i want to have multiple search option ,suppose i have four field ,first name ,lastname ,city ,state. the client can enter this his crietria in any of the above field ,and i want search all records which satisfied the creitria example user enter firstname---mc lastname---john city---new jersy state-new york
3
2700
by: Bjorn Sagbakken | last post by:
What is the best way to read single field values from a dataset? The dataset is populated with a customer record, showing well in a gridview. But I also want to read the single field values, like adress, phone, and so on. Bjorn
1
2232
AutumnsDecay
by: AutumnsDecay | last post by:
Hey there everyone. I've been searching through the pages here and out on the internet, and I can honestly say I cannot find what I'm looking for. What I'm in need of, for a client of mine, is the appropriate CSS / HTML code the insert a search bar onto the site. HOWEVER, the search input field needs to be custom. I've seen it done before, but am not able to determine how, exactly, it's done. I don't want the traditional OS input fields...
1
1565
by: nathanwb | last post by:
I have a small app that allows users to send messages back and forth to each other. I have a place that shows there messages and they can click on a message to read. I have a field in the table called "isread" this defaults to 0 when someone enters a new field and its directed to another user. This is a way that I can show the new message is new and unread. What I would like to do is when a user clicks on one of his/her messages it would...
4
1926
by: migi48 | last post by:
Hi! I'm trying to do a multiple search in my php code. I have an input text field where I input my wanted values then when I click the search button, An html table would show all my searched values from my database table. For example, I want to search multiple names(mark, jake, john, michael) <-- this is typed in a single text field separated by commas. Then it will go to another page which will show all records from my database having a...
5
4227
by: Doicare | last post by:
Hi all I am facing a problem in storing an array of integers to an OLE object field in the database, the used code for this action is listed below: Sub Import_data() Dim oAccesss As New ADODB.Connection
7
1395
by: cdutcher | last post by:
First timer question here: In a customer data table, for each customer I have a field that includes dates in a single field. Example: Name Dates Steve 87,91,01,05,11,12 Bob 99, 03 Ann 01,05,06 In the criteria field of a query, I would like to be able to determine who has at least three dates in the field. Any advice?
0
8987
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...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6793
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
6073
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
4597
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...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
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.