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?
7 1129 ADezii 8,834
Recognized Expert Expert - 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:
- Component A,Component G,Component Q,Component Z
- 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.
- 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.
I think this might be of help ![](https://bytes.com/attachment.php?attachmentid=8786)
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
Can't wait ADezii, we tried a lot of solutions, but the result of the search was always wrong
I will wait yours
Thank you Phil,
we will try it early tomorow morning and be back to you
ADezii 8,834
Recognized Expert Expert - 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.
- 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.
- 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:
- Component A,Component B,Component C, etc...
- You can change the Delimiter if you like by simply changing it in the Constant
- 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.
- P.S. - All the Code exists in a simple Event Procedure for the sake of simplicity.
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 -
Sub FilterForm()
-
-
Dim Fltr As String
-
-
If SelectMediaType > 0 Then ' Media Type not all
-
Fltr = "MediaTypeID = " & SelectMediaType
-
End If
-
-
' If we return no records, tempotarily remove the filter
-
If Me.RecordsetClone.RecordCount = 0 Then
-
Me.FilterOn = False
-
End If
-
-
TxtFilter.SetFocus
-
-
If Left(TxtFilter.Text, 1) = "~" Then ' Don't allow a tilde as first letter
-
TxtFilter.Text = ""
-
End If
-
-
Fltr = "(Drugs Like '*" & Replace(Me.TxtFilter.Text, "'", "''") & "*'"
-
Fltr = Replace(Fltr, "~", "*' OR Drugs Like '*")
-
Fltr = Fltr & " OR Component Like '*" & Replace(Me.TxtFilter.Text, "'", "''") & "*'"
-
Fltr = Replace(Fltr, "~", "*' OR Component Like '*")
-
Fltr = Fltr & ")"
-
-
Me.Form.Filter = Fltr
-
Me.FilterOn = True
-
-
-
Me.TxtFilter.SetFocus
-
-
' Move the cursor to the end of the input text box.
-
If Me.RecordsetClone.RecordCount = 0 Then
-
Exit Sub
-
End If
-
-
Me.TxtFilter.SelStart = Len(Me.TxtFilter.Text)
-
-
End Sub
-
Phil
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. - Private txtFilter_AfterUpdate()
-
Dim strWhere As String, strSep As String
-
Dim astrComponent() As String
-
Dim varComponent As Variant
-
-
strSep = ","
-
With Me
-
astrComponent = Split(.txtFilter, strSep)
-
For Each varComponent In astrComponent
-
strWhere = strWhere _
-
& " OR ([ComponentList] Like '*" & varComponent & "*')"
-
Next varComponent
-
strwhere = Mid(strWhere, 5)
-
If strWhere <> .Filter Then .Filter = strWhere
-
.FilterOn = (.Filter > "")
-
End With
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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,
|
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
|
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
| |
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...
|
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...
|
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...
|
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
|
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?
|
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:
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,...
|
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...
|
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...
|
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: 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...
| |