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

How to apply filter in a query?

180 100+
I have a query name ICISquery, table field names are ARE of Employee, Date of ARE, Item Description and Remarks.
The table field ARE of Employee is a name of employee.
ICISquery has a 10000 records. I have a form name (home) in this form has a combolist and its row source are the name of employees. I have another form name (list) in datasheet view. when i click one of the employee in combolist, the list form will show up and its recordsource is ICISquery. But i want ICISquery will show only the records of employee i have clicked. For example, i click Juan Reynulfo, the list form will show up and contains only the records of Juan Reynulfo. Is this the work of filter in a query? If so, how can i apply this filter in query when you call it?
Dec 27 '11 #1

✓ answered by Mihail

Hi again, eneyardi.
Fortunately for you I know what you wish from this thread:
How to shorten codes that using if, else and end if?
Because from actual thread I can't understand :).

So, one way to do this is to make a new module (or use an existing one.
In this module delare a PUBLIC variable. Say strName and create a PUBLIC function (say fGetName)
Something like this:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public strName As String
  4.  
  5. Public Function fGetName() As String
  6.     fGetName = strName
  7. End Function

In your query, in the field ARE criteria row, write: fGetName().

Close the query and the module (of course save the changes).

Now, go to your combo box (in design view) and, under On Click event write this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboName_Click()
  2.     strName = ComboName
  3. End Sub

That must be all to do.
From now to ever, when you select a new name from your combobox this name will be stored in strName variable. So, when you run the query (or something else like a form or a report based on this query) the query itself will apply (from the criteria row) the function fGetName which will return the value stored in strName (the name you preview selected in your combo box).

Hope you understand the technique and how it work even my English is not very good.

11 15055
Mihail
759 512MB
Hi again, eneyardi.
Fortunately for you I know what you wish from this thread:
How to shorten codes that using if, else and end if?
Because from actual thread I can't understand :).

So, one way to do this is to make a new module (or use an existing one.
In this module delare a PUBLIC variable. Say strName and create a PUBLIC function (say fGetName)
Something like this:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public strName As String
  4.  
  5. Public Function fGetName() As String
  6.     fGetName = strName
  7. End Function

In your query, in the field ARE criteria row, write: fGetName().

Close the query and the module (of course save the changes).

Now, go to your combo box (in design view) and, under On Click event write this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboName_Click()
  2.     strName = ComboName
  3. End Sub

That must be all to do.
From now to ever, when you select a new name from your combobox this name will be stored in strName variable. So, when you run the query (or something else like a form or a report based on this query) the query itself will apply (from the criteria row) the function fGetName which will return the value stored in strName (the name you preview selected in your combo box).

Hope you understand the technique and how it work even my English is not very good.
Dec 27 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
That is certainly one way of doing, and under some circumstances can be very usefull.

I will just for good measure mention another way of doing it:

Presume you have your report set up intially to show all records of all employees. You can also choose to open the report and apply the filter at the same time.

This could be done like so, presuming you have a simple combobox (comboSelectName) listing just the name:
Expand|Select|Wrap|Line Numbers
  1. Dim strName as string
  2. strName=Me.ComboSelectName
  3.  
  4. Dim strFilter as string
  5. strFilter="EmployeeName='" & strName & "'"
  6.  
  7. Docmd.OpenReport "NameOfReport",acViewPreview,,strFilter
Now this will open the report in preview mode, with the filter applied. Its a very usefull feature. The same feature can also be used for forms btw.
Dec 27 '11 #3
eneyardi
180 100+
That's exactly what i'm looking for. thank you guys! I'm excited to apply that on my simple program, I'll give you the update later.
Dec 28 '11 #4
eneyardi
180 100+
Expand|Select|Wrap|Line Numbers
  1. Dim strName As String
  2.  strName = Me.Combo238
  3.  
  4.  Dim strFilter As String
  5. strFilter = "EmployeeName='" & strName & "'"
  6.  
  7. DoCmd.OpenForm "list", acNormal, strFilter
Smiley It shows all the records strfilter not working.
The Recordsource of form name (list) is QueryofMasterlist the field EmployeeName = Combo238 rowsource
Dec 28 '11 #5
eneyardi
180 100+
Mihail i followed your instructions but is not working, i don't know what is my fault. The recordsource became blank
Dec 28 '11 #6
Mihail
759 512MB
Remove all information from your database, ZIP it and attache it to your next post.
Before removing information be sure you make a copy of your database (for safe).

I can think about some reasons that my code make an empty record source:
First can be that you don't use PUBLIC variable and/or function. I don't know if you use Option Explicit statement in yours modules.
The second reason can be that your Combo238 has the first column hidden.
I assume that Combo238 is a bound control. If it is not then we are in war with the wind mills.

I have no idea why Smiley's code give you ALL the records ?!?!
Have you an explication, Smiley ? (you know: I try to learn a little bit SQL. Thank you !)
Dec 28 '11 #7
NeoPa
32,556 Expert Mod 16PB
Please review [code] Tags Must be Used. After over a hundred posts you shouldn't still be posting this nonsense so that other people have to go around after you tidying up.

I will simply delete any of your posts I see in future if they contain untagged code.
Dec 28 '11 #8
eneyardi
180 100+
I'm sorry neopa, I'll do that next time.
Dec 28 '11 #9
eneyardi
180 100+
Mihail thanks alot it works now! I only forgot to save. hehehe.
Dec 28 '11 #10
Mihail
759 512MB
So, one query and five lines of code.
Is now enough short for you ? :)

Glad to help you.
Dec 28 '11 #11
eneyardi
180 100+
Yup, it's a big help for me. Because we're using the program in LAN base, interaction speed improves alot. Thank you!
Dec 29 '11 #12

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

Similar topics

0
by: MaryD | last post by:
Is there any way to use the enter key - or a function key - as the Apply Filter when a form is opened in FilterByForm mode? I can see the value of function keys and the enter key when the form is...
4
by: Iyhamid | last post by:
Hi I am looking for codes to filter and apply filter to my data base using access
3
by: mattscho | last post by:
Hi All, Trying to create a set of 3 buttons in a form that have the same effect as the "Filter by Form", "Apply Filter" and "Remove Filter" Buttons on the access toolbar. Help would be muchly...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
2
by: Nhoung Ar | last post by:
Can anybody out there help me please on apply filter in MS Access. I have a form that create from the query, which contain field chidid (text field), in the form footer, I add the button to open...
8
by: Gari | last post by:
Hello, I am trying to build a filter query with some AND and OR. I have three text boxes and 5 check boxes. The checkboxes are linked via code to other textboxes for the purpose of the query. ...
3
by: Supermansteel | last post by:
I am trying to run a Apply filter for everytime someone opens Form_CC it will only show the Test (Test_ID) they are working on. This seems to be the closest I have gotten to filtering it correctly,...
1
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
3
by: dbdb | last post by:
hi guys need your suggestion how can i apply filter for my date variable data type i have a form name transaction and i have a text box on it named : start and finish i need to apply...
10
by: dbdb | last post by:
Hi, i create a chart in ms access based on my query, then i want my chart when is it open is only show value based on my criteria. i'll try to used it in the properties apply filter using the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.