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 :)
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 : - Private Sub btnFilter_Click()
-
Dim strFilter As String
-
-
With Me
-
If .txtFindCardNumber > "" Then
-
strFilter = Replace(.txtFindCardNumber, ", ", ",")
-
strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')"
-
End If
-
-
.Filter = strFilter
-
.FilterOn = (strFilter > "")
-
End With
-
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
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
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 : - How to provide an interface that enables multiple items to be input.
- 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.
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. :)
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 :-)
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
@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?
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 : - [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 : - [FieldName] In('Bob','John','Valerie','Alex')
This is easily accomplished by : - strFilter = "[FieldName] In('" & Replace(Me.txtX, ",", "','") & "')"
I tried your code. But I always end up a syntax error on strFilter. :( - Option Compare Database
-
-
Private Sub btnFilter_Click()
-
Dim strFilter As String, strOldFilter As String
-
-
strOldFilter = Me.Filter
-
-
If Me!txtFindCardNumber > "" Then _
-
strFilter = "[Card_Number] In('" & Replace(Me.txtFindCardNumber, ",", "','") & "')"
-
-
If strFilter > "" Then strFilter = Mid(strFilter, 6)
-
If strFilter <> strOldFilter Then
-
Me.Filter = strFilter
-
Me.FilterOn = (strFilter > "")
-
End If
-
-
End Sub
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: - strFilter = "[Card_Number] In('5299672017819116','5299671118593117','5299671606423116','5299671934335115')"
This is the the actual code I have right now. - If Me!txtFindCardNumber > "" Then _
-
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
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 - Private Sub btnFilter_Click()
-
Dim strFilter As String
-
-
If Me!txtFindCardNumber > "" Then _
-
strFilter = "[Card_Number] In('" & Replace(Me.txtFindCardNumber, ", ", "', '") & "')"
-
-
If strFilter > "" Then
-
Me.Filter = strFilter
-
Me.FilterOn = (strFilter > "")
-
End If
-
-
End Sub
-
CHEERS!
migi48
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 ...".
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 : - Private Sub btnFilter_Click()
-
Dim strFilter As String
-
-
With Me
-
If .txtFindCardNumber > "" Then
-
strFilter = Replace(.txtFindCardNumber, ", ", ",")
-
strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')"
-
End If
-
-
.Filter = strFilter
-
.FilterOn = (strFilter > "")
-
End With
-
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.
@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 -
Private Sub btnFilter_Click()
-
Dim strFilter As String
-
-
With Me
-
If .txtFindCardNumber > "" Then
-
strFilter = Replace(.txtFindCardNumber, ", ", ",")
-
strFilter = "[Card_Number] In('" & Replace(strFilter, ",", "','") & "')"
-
End If
-
-
.Filter = strFilter
-
.FilterOn = (strFilter > "")
-
End With
-
End Sub
-
-
NeoPa 32,556
Expert Mod 16PB
Always pleased to help. It's why I do it - because I enjoy it :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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)
|
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...
|
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...
|
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...
|
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...
|
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... ...
|
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...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
| |