473,544 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter on Form

24 New Member
Hi Experts,

I have searched all over the internet to find a solution but couldn’t find anything that made it easy for me.

I am a newbie to creating access DB (I see a lot of newbie’s come here) and I am trying to teach myself VB, but I am not there yet.

I have a DB in access 2003, on my main form [Patients] its source is from a
qry [Qry_All_Patiens], which is created from table[Tbl_All_Patient s]. One of the fields available on the form is PTstatus. The patient can have several statuses

EX:

PT Status: A, B, C, D, E, F, 4, 8, 1

I created a table with all the different patient status [Tbl_Status]. I would like to create a combo box on the form with this table (Tbl_Status) that will allow me to filter by status. So if I wanted to look at just patients in status 4 I can just filter it and then remove the filter so that I can go back to all the records.

Is there a way I can code the combo box to do that. If I don't need to use VB, what else can I do to get this done. If it can’t be done please let me know. I don’t know what can be done or cannot be done in VB. Thanks for any feedback.
Nov 15 '06 #1
11 5309
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Experts,

I have searched all over the internet to find a solution but couldn’t find anything that made it easy for me.

I am a newbie to creating access DB (I see a lot of newbie’s come here) and I am trying to teach myself VB, but I am not there yet.

I have a DB in access 2003, on my main form [Patients] its source is from a
qry [Qry_All_Patiens], which is created from table[Tbl_All_Patient s]. One of the fields available on the form is PTstatus. The patient can have several statuses

EX:

PT Status: A, B, C, D, E, F, 4, 8, 1

I created a table with all the different patient status [Tbl_Status]. I would like to create a combo box on the form with this table (Tbl_Status) that will allow me to filter by status. So if I wanted to look at just patients in status 4 I can just filter it and then remove the filter so that I can go back to all the records.

Is there a way I can code the combo box to do that. If I don't need to use VB, what else can I do to get this done. If it can’t be done please let me know. I don’t know what can be done or cannot be done in VB. Thanks for any feedback.
Firstly, thank you for clearly explaining the problem it makes it easier to help you.

Yes you can do this. Create a combo box called for example cboStatus based on your table TblStatus.

Then create an After Update event on the combo box as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboStatus_AfterUpdate()
  3. Dim strFilter As String
  4.  
  5.     strFilter = "select * from  [Qry_All_Patients] WHERE PTstatus='" & cboStatus & "';"
  6.  
  7.     Me.RecordSource = strFilter
  8.     Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
To reset the form to show all ot the records.

The easiest way to do it is to create a reset command button. Put a command button on the form. Call it cmdReset and put in the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdReset_Click()
  3. Dim strFilter As String
  4.  
  5.     strFilter = "select * from  [Qry_All_Patients];"
  6.  
  7.     Me.RecordSource = strFilter
  8.     Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
Nov 15 '06 #2
Umoja
24 New Member
Wow! it worked perfectly. Thank you very much.

I was wondering is there a way to reset the combo box after removing the filter. This is not a big deal, I'm really happy it is working.
Thank you!
Nov 16 '06 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Wow! it worked perfectly. Thank you very much.

I was wondering is there a way to reset the combo box after removing the filter. This is not a big deal, I'm really happy it is working.
Thank you!
Add a line to the reset button code as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdReset_Click()
  3. Dim strFilter As String
  4.  
  5.   strFilter = "select * from [Qry_All_Patients];"
  6.  
  7.   Me.RecordSource = strFilter
  8.   Me.Requery
  9.   Me.cboStatus = Null
  10.  
  11. End Sub
  12.  
  13.  
Nov 16 '06 #4
Umoja
24 New Member
It works, Thank you!
Nov 16 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
It works, Thank you!
You're welcome.
Nov 16 '06 #6
Umoja
24 New Member
I have a quick question, could I use the same code abovr to create a filter for another field on the form. I want to be able to filter by [PTstatus] or [PTFNCLS]. From the code above I would just change the field/table name correct?
Nov 16 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
I have a quick question, could I use the same code abovr to create a filter for another field on the form. I want to be able to filter by [PTstatus] or [PTFNCLS]. From the code above I would just change the field/table name correct?
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboStatus_AfterUpdate()
  3. Dim strFilter As String
  4.  
  5.     strFilter = "select * from  [Qry_All_Patients] WHERE PTstatus='" & cboStatus & "';"
  6.  
  7.     Me.RecordSource = strFilter
  8.     Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
This works for the PTstatus because the cboStatus is based on PTStatus so you would need a new combo box based on PTFNCLS (e.g. cboFncls) and a new afterupdate event on this combo box as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboFncls_AfterUpdate()
  3. Dim strFilter As String
  4.  
  5. strFilter = "select * from  [Qry_All_Patients] WHERE PTFNCLS='" & cboFncls & "';"
  6.  
  7. Me.RecordSource = strFilter
  8. Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
The reset button is fine as it is.

Mary
Nov 16 '06 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
BTW, this assumes PTFNCLS is a text field, if it is a number remove the single quotes enclosing the cboFncls.



Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboStatus_AfterUpdate()
  3. Dim strFilter As String
  4.  
  5.     strFilter = "select * from [Qry_All_Patients] WHERE PTstatus='" & cboStatus & "';"
  6.  
  7.     Me.RecordSource = strFilter
  8.     Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
This works for the PTstatus because the cboStatus is based on PTStatus so you would need a new combo box based on PTFNCLS (e.g. cboFncls) and a new afterupdate event on this combo box as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cboFncls_AfterUpdate()
  3. Dim strFilter As String
  4.  
  5. strFilter = "select * from [Qry_All_Patients] WHERE PTFNCLS='" & cboFncls & "';"
  6.  
  7. Me.RecordSource = strFilter
  8. Me.Requery
  9.  
  10. End Sub
  11.  
  12.  
The reset button is fine as it is.

Mary
Nov 16 '06 #9
nico5038
3,080 Recognized Expert Specialist
Personally I prefer to use the right-click popup menu to do the filtering of tables, queries and/or forms.
Check my Right-Click instruction at www.geocities.com/nico5038 for the info I give my users and thus save myself a lot of coding...

Nic;o)
Nov 16 '06 #10

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

Similar topics

1
7831
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside from queries. Let me just add that Allen Browne excellent article about this subject may not apply to this scenario on an elementary level. (Here's...
0
6457
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the report are based on the same View addressed in the Record Source of both as 'dbo.CLMain_vw'. The View resides in a SQL Server 2000 database. There are...
2
9779
by: Andante.in.Blue | last post by:
Hi everyone! I was wondering if there is a away to use Access 97's build in filter-by-form function but restrict its effect to just the subform. I have a parent form that shows the major divisions of the company, and a subform that is linked so that it displays all the jobs within the division in the parent form. I also want the ability...
3
6597
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where the text value is on a different table. The me.filter is then a text instead of the id-number from the lookup table. This causes the report to prompt...
1
4538
by: jeffgeorge | last post by:
Hi all. Trying to move Filter By Selection, Filter By Form, and Apply/Remove Filter directly into my form. No luck. Is there anyway to move them into the header of the form or, as another option, is the code needed to write out a filter worth pursuing? jg
7
6265
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals. I can do this the first time the form loads.
8
6515
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and there are many examples. BUT, they fail sometimes. The techique is to pass the form's Me.filter as the "where condition" in a Docmd.openreport...
2
5028
by: Salad | last post by:
I have a log file with a list of records. The log file can be unfiltered or filtered. I have a command button to call a data entry form from the log. At first I was only going to present the record the user selected. Then I thought, what the heck, give the user all of them but start out at the record the user is currently on. If I...
2
2826
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL record source that returns an ID field and a Text field. Next to each combo box is two buttons, one that 'Applys' the filter of the sub-form to the...
1
6776
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from...
0
7373
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...
0
7625
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. ...
0
7781
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...
1
7389
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5928
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3427
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...
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
677
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...

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.