473,385 Members | 2,003 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,385 software developers and data experts.

Form Filtering

28
Hi!

I just want to ask if it is posible to make a multiple search/filter of records in a form?

For example, I have a form(frmApplications) that has a record source connected to a table (tblApplications). Then I want to view and edit records which App_Num are equal with "5299672017819116", "5299671118593117", "5299671606423116", and so on. Filter feature of MS ACCESS only allows me to view and edit filtered records one by one. Is there a way I can view and edit all these filtered records of App_Nums in one form(hopefully in a Continuous Form)?

Thank you so much :)
Feb 7 '12 #1

✓ answered by NeoPa

Migi48:
Please tell me what's wrong with it. Thanks! :D
I see nothing wrong with the code here. What data is passed in Me.txtFindCardNumber?

Migi48:
I just included a space after the comma(,) from the code you gave me :D
Not a good plan. This may get past the problem of the data but doesn't fix the data. The operator is entering the data incorrectly (a space after the comma is not correct - and explains why it was failing previously). Your code now only works with incorrectly entered data.

Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnFilter_Click()
  2.     Dim strFilter As String
  3.  
  4.     With Me
  5.         If .txtFindCardNumber > "" Then
  6.             strFilter = Replace(.txtFindCardNumber, ", ", ",")
  7.             strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')"
  8.         End If
  9.  
  10.         .Filter = strFilter
  11.         .FilterOn = (strFilter > "")
  12.     End With
  13. End Sub
This will allow the operator to make that particular mistake without penalising them for entering the data correctly. Only the comma (,) should be entered between valid items.

PS. Setting .Filter should not be dependent on whether a value has been entered - otherwise clearing the filter would have no effect. See my code for how it should be done properly.

14 3399
MikeTheBike
639 Expert 512MB
Hi

The short answer is yes, but we would need to know how you intend to impliment the filter for the required App_Num's.

For instance, you could have a multi-select list box and a button to apply the filter, which would build a filter criteria from the selected items in code and then apply it to the form.

This would of course require some VBA knowlege!

There are other ways to do this, perhaps you could indicate how you see it operating.


MTB
Feb 7 '12 #2
NeoPa
32,556 Expert Mod 16PB
First let me say that you have posted two very similar threads at the same time (How do I Open a Form with Multiple Items Filtered). As there is considerable overlap I suggest this is a self-defeating approach. I will delete the other question for now while the main concepts of the filtering issue are dealt with in here. If, at that point, you feel you'd like to ask about applying those concepts to opening a separate form pre-filtered to your choices, then you should do that then, from a position of better understanding.

As far as filtering within the same form goes, there are two fundamental issues you need to deal with :
  1. How to provide an interface that enables multiple items to be input.
  2. How to filter the records based on that list.

MTB has already offered some thoughts on A, which seem sensible given a finite list from which to choose values. If that is not the case then a simpler TextBox control allowing the entry of a list of items separated by a character such as a comma (,) would be a viable alternative.

For filtering within and between forms you can find all you need at Example Filtering on a Form. It even has an example database to download and experiment with, and explains how various types of data should be formatted in the filter string.
Feb 7 '12 #3
migi48
28
Hi guys! Thanks for replying! First of all, I admit that I'm new at access and VBA coding so please forgive me. :D

@MikeTheBike - I actually visualize the form to have multiple textboxes where I could input different App_Num's I want to find. Then with a click of a button, I want to see only the records which I have input. (doesn't really matter if it should be on the same form or not) But I want it editable and not in a query(since I believe queries are only for viewing). :)

@NeoPa - Sorry for the other thread. I repost this question simply because I thought I found the other one more difficult to understand. Thank you for directing me to an article. I would try to read and understand that and maybe that could answer my question. :)
Feb 8 '12 #4
NeoPa
32,556 Expert Mod 16PB
No need to apologise really. The questions were different enough that it was hard for me (and I have a lot of experience in the forums) to know if it was a problem or not. It would be unreasonable to expect you to appreciate it quite so well.

Anyway, you may like to consider some other aspects of having multiple TextBox controls to allow entry of this information. Do you have a finite size for the list? If not then how many controls do you design?

When you've designed it, you will only have to put all the values together into a comma (,) separated string anyway to include in your filter (using the In() facility).

It's not an impossible approach, but it may make your life more complicated than necessary. Ultimately how you handle it is your choice of course :-)
Feb 8 '12 #5
migi48
28
Hi NeoPa!

I have read your article on Filtering on a form. However it only filters/finds one account at a time. I would want my form to display multiple accounts(just to relate with your article). Considering that I would input multiple account codes(unique codes) in multiple textboxes(Let's say 5 textboxes). And after clicking a button, the form would show me the 5 accounts which I could edit. :D
Feb 8 '12 #6
migi48
28
@NeoPa

I see. So I can just input 5 values in one textbox separating them with commas(,)? How can I separate these (in code) values when I need to filter them in the module?
Feb 8 '12 #7
NeoPa
32,556 Expert Mod 16PB
Migi48:
How can I separate these (in code) values when I need to filter them in the module?
You don't need to. That's the point. The filter should look like :
Expand|Select|Wrap|Line Numbers
  1. [FieldName] In(1,6,9,45,9923)
That is exactly what you would expect the operator to enter into your TextBox. If it's string values required then it sould look like :
Expand|Select|Wrap|Line Numbers
  1. [FieldName] In('Bob','John','Valerie','Alex')
This is easily accomplished by :
Expand|Select|Wrap|Line Numbers
  1. strFilter = "[FieldName] In('" & Replace(Me.txtX, ",", "','") & "')"
Feb 8 '12 #8
migi48
28
I tried your code. But I always end up a syntax error on strFilter. :(

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub btnFilter_Click()
  4.     Dim strFilter As String, strOldFilter As String
  5.  
  6.     strOldFilter = Me.Filter
  7.  
  8.     If Me!txtFindCardNumber > "" Then _
  9.         strFilter = "[Card_Number] In('" & Replace(Me.txtFindCardNumber, ",", "','") & "')"
  10.  
  11.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  12.     If strFilter <> strOldFilter Then
  13.         Me.Filter = strFilter
  14.         Me.FilterOn = (strFilter > "")
  15.     End If
  16.  
  17. End Sub
Feb 8 '12 #9
migi48
28
Hi NeoPa! I got the filter working for me :) Unfortunately, only one record can be shown at a time. I want my strFilter to look like these:
Expand|Select|Wrap|Line Numbers
  1.  strFilter = "[Card_Number] In('5299672017819116','5299671118593117','5299671606423116','5299671934335115')" 
This is the the actual code I have right now.

Expand|Select|Wrap|Line Numbers
  1.  If Me!txtFindCardNumber > "" Then _
  2.         strFilter = "[Card_Number] In('" & Replace(Me.txtFindCardNumber, ",", "','") & "')" 
The Card_Number's would come from a textbox (txtFindCardNumber) only separated by commas(,) I think there is something wrong with this line that's why it only gives me the first Card_Number which I have input in the textbox (txtFindCardNumber). Please tell me what's wrong with it. Thanks! :D
Feb 8 '12 #10
migi48
28
Hi NeoPa! :D

I have finally done it! :D Thank you so much for your HELP and PATIENCE! :D I just included a space after the comma(,) from the code you gave me :D Here's my final code. I hope this thread could help a lot of newbies like me :D

Expand|Select|Wrap|Line Numbers
  1.  Private Sub btnFilter_Click()
  2.     Dim strFilter As String
  3.  
  4.     If Me!txtFindCardNumber > "" Then _
  5.         strFilter = "[Card_Number] In('" & Replace(Me.txtFindCardNumber, ", ", "', '") & "')"
  6.  
  7.     If strFilter > "" Then
  8.         Me.Filter = strFilter
  9.         Me.FilterOn = (strFilter > "")
  10.     End If
  11.  
  12. End Sub
  13.  
CHEERS!
migi48
Feb 8 '12 #11
NeoPa
32,556 Expert Mod 16PB
Migi48:
I tried your code. But I always end up a syntax error on strFilter. :(
Line #11 is extraneous here. It's only required if you have multiple potential strings - all starting with " AND ...".
Feb 8 '12 #12
NeoPa
32,556 Expert Mod 16PB
Migi48:
Please tell me what's wrong with it. Thanks! :D
I see nothing wrong with the code here. What data is passed in Me.txtFindCardNumber?

Migi48:
I just included a space after the comma(,) from the code you gave me :D
Not a good plan. This may get past the problem of the data but doesn't fix the data. The operator is entering the data incorrectly (a space after the comma is not correct - and explains why it was failing previously). Your code now only works with incorrectly entered data.

Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnFilter_Click()
  2.     Dim strFilter As String
  3.  
  4.     With Me
  5.         If .txtFindCardNumber > "" Then
  6.             strFilter = Replace(.txtFindCardNumber, ", ", ",")
  7.             strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')"
  8.         End If
  9.  
  10.         .Filter = strFilter
  11.         .FilterOn = (strFilter > "")
  12.     End With
  13. End Sub
This will allow the operator to make that particular mistake without penalising them for entering the data correctly. Only the comma (,) should be entered between valid items.

PS. Setting .Filter should not be dependent on whether a value has been entered - otherwise clearing the filter would have no effect. See my code for how it should be done properly.
Feb 8 '12 #13
migi48
28
@NeoPa

I did what you suggested and it's now working pefectly. :D
Thank you so much for correcting me and explaining how it should be done. :D More power to expert programmers like you! :D

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnFilter_Click() 
  2.     Dim strFilter As String 
  3.  
  4.     With Me 
  5.         If .txtFindCardNumber > "" Then 
  6.             strFilter = Replace(.txtFindCardNumber, ", ", ",") 
  7.             strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')" 
  8.         End If 
  9.  
  10.         .Filter = strFilter 
  11.         .FilterOn = (strFilter > "") 
  12.     End With 
  13. End Sub 
  14.  
  15.  
Feb 8 '12 #14
NeoPa
32,556 Expert Mod 16PB
Always pleased to help. It's why I do it - because I enjoy it :-)
Feb 8 '12 #15

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

Similar topics

3
by: 8leggeddj | last post by:
Hello, I am having a problem when using access xp as a frontend for sql server 2000. I have been trying to update a number of stored procedures (Just simple adding fields etc) which results in...
5
by: zqhpnp | last post by:
class String { public: String& operator=(const String& str); private: char* pdata; } String& String::operator=(const String& str) { if(this==&str)
3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
3
by: SecretCharacter | last post by:
I have a project going on to store data for inventory information. Creating a database with access makes me realise all things like the data tables and user interface(forms) and queries are all...
1
by: @ndy | last post by:
Hey fella's, I have a table with an Id and LineId in Access. I have these Id's also in an Excel sheet. Is it possible to find the Id's in the Excel sheet corresponding from Acces and then adapt...
9
by: MLH | last post by:
I need a fundamental explanation of Class Modules - something suitable for newbies. Access 2.0 didn't seem to focus on them very much. Now that I'm using Access 97, it seems they're everywhere. thx...
1
by: raehippychick | last post by:
Hi all I am pretty new to Access and am trying to run a query that find only records in a field that relate to 47 different 'codes' Basically I tried a simple... ...
2
by: ccwells | last post by:
Hi, I am a novice to VB, using Access 2003 on a XP-SP2 platform, and I have a small database for tracking expenses, and want to be able to filter my expense report by date. I currently have a...
2
by: poteatc | last post by:
I want to filter my reports according date and time. I am already successful with filtering dates and times, but not overnight. I want to filter according to a shift that starts for example,...
3
by: zandiT | last post by:
Hello I have an access report and im using a query to filter the report using Date parameters eg Start Date-12 May 2009 and End Date-30 September 2009. the query works perfectly. My problem is...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.