473,386 Members | 1,693 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,386 software developers and data experts.

Search Multiple Data : Textbox and Search Button in Form

spideynok
Hi! I had a code that can search, just enter any keyword like. If I want to search "Access" I can put Acc only and then it will show me all record that has "Acc" on the database like Access, Accelerate, etc.

My question is. It is possible if I also do that in multiple search? Using comma as a separator?

For example : I will put [Acc, Ex] on my textbox. Is it possible for it to show me the record like.
•Access
•Accelerate
•Accurate
•Example
•T-Rex
•Excel

Is it possible? Thank you in advanced!
Mar 19 '12 #1

✓ answered by NeoPa

Fundamentally you've done a great job, and posting exactly what you've done with the legend makes it much easier to focus on what you've done.
  1. All the replacements you made seem fine. Line #10 (of your code) however, changes %F to %Me.Text24, which is unnecessary. It will still work perfectly, but the string is arbitrary (It doesn't matter what the string is as long as the substring in the first parameter matches the string in the second one). It's easier to leave that as %F.
  2. The code produces the value for the filter. I imagine that works perfectly. You still need to apply the filter though. The code doesn't include that part as it was assumed to be understood. I'll include it in this example though, on the assumption you wish to filter the current form (You didn't say what you were doing with it so it made sense you didn't need that explained or illustrated).
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Command26_Click()
    2.     Dim strFilter As String, strFilters() As String
    3.     Dim intX As Integer
    4.  
    5.     With Me
    6.         strFilters = Split(.Text24, ",")
    7.         For intX = 0 To UBound(strFilters)
    8.             strFilter = strFilter & _
    9.                         Replace(" OR ([Card_Number] Like '%F*')", _
    10.                                 "%F", strFilters(intX))
    11.         Next intX
    12.         .Filter = Mid(strFilter, 5)
    13.         .FilterOn = (.Filter > "")
    14.     End With
    15. End Sub

13 5323
NeoPa
32,556 Expert Mod 16PB
Yes. It's possible.

You would need to do it with separate statements ORed together like :
Expand|Select|Wrap|Line Numbers
  1. Dim strFilter As String, strFilters() As String
  2. Dim intX As Integer
  3.  
  4. strFilters = Split([txtFilter], ",")
  5. strFilter = ""
  6. For intX = 0 To UBound(strFilters)
  7.     strFilter = strFilter & _
  8.                 Replace(" OR ([X] Like '%F*')", "%F", strFilters(intX))
  9. Next intX
  10. strFilter = Mid(strFilter, 5)
You will need to replace the names I've used with ones that are in your project as you didn't include this basic information in your question.
Mar 19 '12 #2
Thank You Sir NeoPa.

BTW I changed some names as what you said. I came up with this.

LEGEND
• Text24 = Textbox where I will input the value that I want to search.
• Card_Number = Name of the column where the data stored that I want to search.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command26_Click()
  2.  
  3.     Dim strFilter As String, strFilters() As String
  4.     Dim intX As Integer
  5.  
  6.     strFilters = Split([Text24], ",")
  7.     strFilter = ""
  8.     For intX = 0 To UBound(strFilters)
  9.         strFilter = strFilter & _
  10.                     Replace(" OR ([Card_Number] Like '%Me.Text24*')", "%Me.Text24", strFilters(intX))
  11.     Next intX
  12.     strFilter = Mid(strFilter, 5)        
  13.  
  14. End Sub
uhmm It's not functioning? or did I forgot to change some names? Thank you again sir :)
Mar 20 '12 #3
NeoPa
32,556 Expert Mod 16PB
Fundamentally you've done a great job, and posting exactly what you've done with the legend makes it much easier to focus on what you've done.
  1. All the replacements you made seem fine. Line #10 (of your code) however, changes %F to %Me.Text24, which is unnecessary. It will still work perfectly, but the string is arbitrary (It doesn't matter what the string is as long as the substring in the first parameter matches the string in the second one). It's easier to leave that as %F.
  2. The code produces the value for the filter. I imagine that works perfectly. You still need to apply the filter though. The code doesn't include that part as it was assumed to be understood. I'll include it in this example though, on the assumption you wish to filter the current form (You didn't say what you were doing with it so it made sense you didn't need that explained or illustrated).
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Command26_Click()
    2.     Dim strFilter As String, strFilters() As String
    3.     Dim intX As Integer
    4.  
    5.     With Me
    6.         strFilters = Split(.Text24, ",")
    7.         For intX = 0 To UBound(strFilters)
    8.             strFilter = strFilter & _
    9.                         Replace(" OR ([Card_Number] Like '%F*')", _
    10.                                 "%F", strFilters(intX))
    11.         Next intX
    12.         .Filter = Mid(strFilter, 5)
    13.         .FilterOn = (.Filter > "")
    14.     End With
    15. End Sub
Mar 20 '12 #4
It Works! Thank you thank you thank you sir!

but the thing is. I can't use the textbox as a search box? uhmm when I enter a value. It will filter to 300 data. not including the one I putted?
Mar 20 '12 #5
NeoPa
32,556 Expert Mod 16PB
It was a pleasure to help - especially with such an intelligent reponse in post #3.
Mar 20 '12 #6
hehe Thank you so much sir :)
Mar 20 '12 #7
NeoPa
32,556 Expert Mod 16PB
I'm afraid I didn't even notice there was any follow-on to the question.

Now I see it I have no idea what you mean. What you say doesn't make sense o.O

If you can explain it more clearly I'll see if I can help.

PS. Anyone else interested can continue to follow the thread but I will need to delete the post from redhorse as it's a hijack which is not allowed.
Mar 22 '12 #8
Hi sir. I'm sorry for that unclear question.

What I was saying is that when I click the button which I use as a Search Button using NULL value it filters my 50k++ record into 300 records, and when I put a value on it like a Card Number, It still shows me the 300 records and not looking for the value that I put on the textbox.
Mar 23 '12 #9
NeoPa
32,556 Expert Mod 16PB
It appears there is a problem handling Nulls, although I would expect an error message and a line number if you had this problem - not failed filtering. See below for a fixed version.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command26_Click()
  2.     Dim strFilter As String, strFilters() As String
  3.     Dim intX As Integer
  4.  
  5.     With Me
  6.         strFilters = Split(Nz(.Text24, ""), ",")
  7.         For intX = 0 To UBound(strFilters)
  8.             strFilter = strFilter & _
  9.                         Replace(" OR ([Card_Number] Like '%F*')", _
  10.                                 "%F", strFilters(intX))
  11.         Next intX
  12.         .Filter = Mid(strFilter, 5)
  13.         .FilterOn = (.Filter > "")
  14.     End With
  15. End Sub
However, if a value entered is not being used for the filtering then only you can explain that. That isn't a problem with the code, but with your attempt to implement it. As I have no access to your database I cannot help you there.
Mar 23 '12 #10
Thank you sir. The Null issue was solved. I will try and play on the code on when I enter a value it will look for the value that I enter. Because as of now the code given on post #10, It filters the record to 300 record even I put a Card Number which doesn't exist. Thank you Thank you sir. :)
Mar 23 '12 #11
NeoPa
32,556 Expert Mod 16PB
If you're having that problem then print the .Filter string to the Immediate Pane (See Debugging in VBA).

Add the following code after line #13 :
Expand|Select|Wrap|Line Numbers
  1. Debug.Print .Filter
When it's run and failed to produce the expected output check out what has been printed. If it doesn't answer your question you could try posting the string on here for us to look at.
Mar 23 '12 #12
Hi NeoPa! Thank you thank you so much! The error is on me, The problem is I'm putting the code to the search button on the mainform not on a subform, then when I try to put the code on the search button in the subform. It WORKS!!! THANK YOU THANK YOU THANK YOU!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command26_Click()
  2.         Dim strFilter As String, strFilters() As String
  3.         Dim intX As Integer
  4.  
  5.         With Me
  6.             strFilters = Split(Nz(.Text24, ""), ",")
  7.             For intX = 0 To UBound(strFilters)
  8.                 strFilter = strFilter & _
  9.                             Replace(" OR ([Card_Number] Like '%F*')", _
  10.                                     "%F", strFilters(intX))
  11.             Next intX
  12.             .Filter = Replace(Mid(strFilter, 5), "'", Chr(34))
  13.             .FilterOn = (.Filter > "")
  14.         End With
  15. End Sub
Mar 29 '12 #13
NeoPa
32,556 Expert Mod 16PB
I'm very pleased to hear it Spidey :-)
Mar 29 '12 #14

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

Similar topics

4
by: Dave Smithz | last post by:
Hi there, When filling out a web form on a php page that is submitted to a search which lists the results based on the criteria provided (in the form), all works fine and as expected. ...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
3
by: Stu | last post by:
Hi, I've been looking through the archives but can't find what I'm looking for, or due to my limited experience with Access97, didn't recognize it... I've created a database that is going to be...
3
by: Omar Llanos | last post by:
I have Form1 and Form2 (which is inherited from Form1), and I created a button in Form2 that will fill up a textbox in Form1. What code would do that? I tried the simplest way: //from child...
3
by: D. Shane Fowlkes | last post by:
Sorry for the length of this post. I have created a rather complex form which has a header/line item (parent and child records) structure. It's for an intranet. A screenshot can be seen here: ...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
2
by: R Tipton | last post by:
I have a simple web form with a textbox and a button and further down another textbox and button. My problem is even though I have my cursor placed in the second textbox, the first button is...
0
by: rbmako69 | last post by:
I have a large html table and form, for displaying data and for updating the record data. To make this form look really good, i'm deciding to convert the html form into flash. The page has one...
5
by: Zytan | last post by:
Is it possible (I doubt it) to have multiple default buttons in a form? I have several group controls in a single form, and when the focus is within one of the group controls, I want a specific...
11
by: hkma08 | last post by:
For certain reason, I need to check the validity of a form when submit with many data with shared name. The form looks like this: <form id="upload_form" name="upload_form" onsubmit="return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.