473,386 Members | 1,799 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.

Filters

I was wondering how I can go about inserting code to apply filter's to a form rather than using the filter by form on the form itself.

Thank you
Sep 4 '08 #1
17 1470
NeoPa
32,556 Expert Mod 16PB
When using the DoCmd.OpenForm function, the fourth parameter is WhereCondition.

Check out the full details in Help.
Sep 4 '08 #2
ADezii
8,834 Expert 8TB
It is actually a 2-Step process:
  1. Setting the Filter Property of the Form:
    Expand|Select|Wrap|Line Numbers
    1. Me.Filter = "[LastName] ='Fuller'"
  2. Setting the FilterOn Property of the Form in order to apply the Filter:
    Expand|Select|Wrap|Line Numbers
    1. Me.FilterOn = True
  3. Combined, it would be something similar to:
    Expand|Select|Wrap|Line Numbers
    1. Me.Filter = "[LastName] ='Fuller'"
    2. Me.FilterOn = True
Sep 4 '08 #3
NeoPa
32,556 Expert Mod 16PB
This raises the point of when you want to apply the filter.

If you want to open the form with a pre-prepared filter applied then my earlier response is what you need.

If, however, you want, from within the code of the form itself, to change the filter dynamically, then ADezii's response is what you require.

Now you have both anyway - untold riches ;)
Sep 5 '08 #4
Thank you guys! Well what I was trying to accomplish was exporting a form to excel, but only capturing data that is greater than 0. It works when I manually hit filter by form then apply filter, but I want it to work when I click the button.
Sep 5 '08 #5
NeoPa
32,556 Expert Mod 16PB
Freddie, if what you've posted so far hasn't convinced you already, you need to be much clearer in what you post.

It's not about what you understand, it's about how anyone can understand what you post. Remember we don't know anything about your situation except what you tell us. You're not telling us very much I'm afraid.

Reading between the lines (with a little guesswork thrown in for good measure), I suspect you are after what ADezii was suggesting.

If you need more specific help you will HAVE to start presenting your situation a lot more clearly.
Sep 5 '08 #6
Sorry about that, what I want is to export a form that has different months on a form. For example if we are in January I only want to export January's numbers, but I have a list of people in January so I only want to export the people that have a number that is greater than 0. I am able to grab only the month I am looking for to export by Formatting NOW by month to match the current month. My problem is that when I export, it's exporting everything. So I wanted to run something that would eleviate the problem.
Thank you
Sep 5 '08 #7
NeoPa
32,556 Expert Mod 16PB
I'm sorry I didn't pick up on your earlier post before where you said you want to export a form. I was so confused by the fact that nothing in the post seemed to make any recognisable sense, that I missed this fundamental point.

Queries and tables can be exported, not forms or reports (as far as I'm aware).

Unfortunately, your latest post still talks in terms of selecting "people" whose "numbers" are greater than 0.

People don't live in databases, and very many things in a database are numbers!

If you have a table that somehow tracks people in your database, and that has a numeric field that you need to compare, then for goodness sake how do you expect me to know about any of that unless you tell me. Properly. With the level of detail I will need to be able to answer at least the simplest of questions.

I don't know how I can get this across to you. I seem to have been telling you a number of times without any noticeable effect.
Sep 5 '08 #8
NeoPa
32,556 Expert Mod 16PB
As a further point, you give no indication that you have even tried to implement ADezii's answer to your question.

You do understand that you are expected to try this for yourself, or explain why, for you, this is not possible.
Sep 5 '08 #9
I'm sorry I didn't pick up on your earlier post before where you said you want to export a form. I was so confused by the fact that nothing in the post seemed to make any recognisable sense, that I missed this fundamental point.

Queries and tables can be exported, not forms or reports (as far as I'm aware).

Unfortunately, your latest post still talks in terms of selecting "people" whose "numbers" are greater than 0.

People don't live in databases, and very many things in a database are numbers!

If you have a table that somehow tracks people in your database, and that has a numeric field that you need to compare, then for goodness sake how do you expect me to know about any of that unless you tell me. Properly. With the level of detail I will need to be able to answer at least the simplest of questions.

I don't know how I can get this across to you. I seem to have been telling you a number of times without any noticeable effect.
Okay, this is the problem and yes you can export a form. I have DATA in a table which I would want to only export a certain criteria of that the only problem I am having is that grabbing that data through queries. I have a table that has months and Employee information. I don't know how to grab the information through queries because I only want to grab the current month, so I decided to add a button to only make the current month visible so that when I export it to excel, it will only show this month, I have figured that part out on my form using code, however I want only the current month that has a number greater than 0. I used the code:
Expand|Select|Wrap|Line Numbers
  1. .
  2.     If [Text40] = "September" Then [January].Visible = False
  3.     If [Text40] = "September" Then [February].Visible = False
  4.     If [Text40] = "September" Then [March].Visible = False
  5.     If [Text40] = "September" Then [April].Visible = False
  6.     If [Text40] = "September" Then [May].Visible = False
  7.     If [Text40] = "September" Then [June].Visible = False
  8.     If [Text40] = "September" Then [July].Visible = False
  9.     If [Text40] = "September" Then [August].Visible = False
  10.     If [Text40] = "September" Then [October].Visible = False
  11.     If [Text40] = "September" Then [November].Visible = False
  12.     If [Text40] = "September" Then [December].Visible = False
Now Text40 is using : =(Format(Date(),"mmmm")
Sep 5 '08 #10
I tried ADezii's and it didn't work, It came with an error message saying "Run-Time Error 2001: You canceled the previous operation. and I don't know why it wont work. Yes I understand that I have to try it and I did, I'm sorry it took so long to explain why it didn't work.
Sep 5 '08 #11
NeoPa
32,556 Expert Mod 16PB
Okay, this is the problem and yes you can export a form....
It seems you can export a form. It appears that the options associated with this approach are somewhat limited though. Maybe they expand as you get more familiar with it. Who knows. It's also possible to "Publish" a form (to other MS Office applications). This would include some level of formatting.
... I have DATA in a table which I would want to only export a certain criteria of that the only problem I am having is that grabbing that data through queries. ...
??? Not sure what this means.
...
I have a table that has months and Employee information. I don't know how to grab the information through queries because I only want to grab the current month, so I decided to add a button to only make the current month visible so that when I export it to excel, it will only show this month, I have figured that part out on my form using code, however I want only the current month that has a number greater than 0. I used the code:
Expand|Select|Wrap|Line Numbers
  1. .
  2.     If [Text40] = "September" Then [January].Visible = False
  3.     If [Text40] = "September" Then [February].Visible = False
  4.     If [Text40] = "September" Then [March].Visible = False
  5.     If [Text40] = "September" Then [April].Visible = False
  6.     If [Text40] = "September" Then [May].Visible = False
  7.     If [Text40] = "September" Then [June].Visible = False
  8.     If [Text40] = "September" Then [July].Visible = False
  9.     If [Text40] = "September" Then [August].Visible = False
  10.     If [Text40] = "September" Then [October].Visible = False
  11.     If [Text40] = "September" Then [November].Visible = False
  12.     If [Text40] = "September" Then [December].Visible = False
Now Text40 is using : =Format(Date(),"mmmm")
I can't find any references here to fields where your data is stored (Not controls on the form but fields in the underlying recordset) :S
I get that Me.Text40 has a string value of the current month, but this is a form control. It's being compared with the literal value "September". I can't see why "September" is special in any way. I find your code to be so unusual that I can read very little from it.
Otherwise, I still have nothing to work from. No field names and the undefined "number" I commented on earlier is still there. Just as devoid of meaning as it was before.

I've been racking my brains to find a way we can go forward on this that will make sense to both of us.

I'm horribly afraid (from looking at your posted code) that what you want may not be possible with your current data structure. Can you confirm that in the table (or query) that the form is bound to, you have fields for each month of the year? If so I think we may have a fundamental problem.
Sep 5 '08 #12
NeoPa
32,556 Expert Mod 16PB
I tried ADezii's and it didn't work, It came with an error message saying "Run-Time Error 2001: You canceled the previous operation. and I don't know why it wont work. Yes I understand that I have to try it and I did, I'm sorry it took so long to explain why it didn't work.
If what I am coming to suspect is true, then getting that to work is likely to prove very difficult indeed, even for an experienced developer.

What I suggest you do at this stage (read and respond to earlier post first of course) is to post the table metadata for the table the form is bound to.

Just list all the fields by name and include their type (String; Numeric; Date/Time; etc).

We may find that the way the data is structured is not conducive to filtering in the way you require. That would be bad news indeed, but let's see what we have before we reach that conclusion.

PS. That error message is particularly unhelpful and has confused developers with much more experience than you have. Access can be like that sometimes.
Sep 5 '08 #13
It seems you can export a form. It appears that the options associated with this approach are somewhat limited though. Maybe they expand as you get more familiar with it. Who knows. It's also possible to "Publish" a form (to other MS Office applications). This would include some level of formatting.

??? Not sure what this means.

I can't find any references here to fields where your data is stored (Not controls on the form but fields in the underlying recordset) :S
I get that Me.Text40 has a string value of the current month, but this is a form control. It's being compared with the literal value "September". I can't see why "September" is special in any way. I find your code to be so unusual that I can read very little from it.
Otherwise, I still have nothing to work from. No field names and the undefined "number" I commented on earlier is still there. Just as devoid of meaning as it was before.

I've been racking my brains to find a way we can go forward on this that will make sense to both of us.

I'm horribly afraid (from looking at your posted code) that what you want may not be possible with your current data structure. Can you confirm that in the table (or query) that the form is bound to, you have fields for each month of the year? If so I think we may have a fundamental problem.
That's what I was afraid of, I was trying to make this possible for someone else. It's their database not mine and their structure was wrong compared to how I would have made it and I don't think it's obtainable. I think I may have to write a new database for this person.

A question I do have which I haven't been able to figure out and I hope you may be able to, I have attendance records for each employee (AttendanceID Autonumber) and it has a series of possibilities such as points, sick days, etc. All of which contain certain points depending on the situation for example if an employee used 1 sick day they would receive 2 points. I made a table called Reason Table which has all the different criteria. My question is if an employee received points in any month they would not be eligable for perfect attendance and that's my problem. How can I get Access to exclude an employee through their employeeID number where they didn't receive an infraction that would have given them points or affected their perfect attendance? I am using Access 2003. Thank you.
Sep 10 '08 #14
NeoPa
32,556 Expert Mod 16PB
Freddie, it's probably better if you ask this question in a separate thread. Post a link to your thread in here by all means and I'll pop over and have a look.

You will, of course, need to specify the question more clearly and provide some detail to help someone understand what it's about.

The layout of the tables would help greatly to understand the problem.

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Never use TABs in this as the layout gets mucked up. Use spaces and all is fine.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. StudentID       AutoNumber    PK
  3. Family          String        FK
  4. Name            String
  5. University      String        FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Sep 10 '08 #15
I will post a new question, Thank you NeoPa
Sep 10 '08 #16
NeoPa
32,556 Expert Mod 16PB
No worries :)

Post a link in here so I can find it easily.
Sep 10 '08 #17
New Table?

Here you go, Thanks again!
Sep 10 '08 #18

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

Similar topics

1
by: shumaker | last post by:
I'm trying to defeat persistant filters with the following code in Close, and also in Unload: Private Sub Form_Close() DoCmd.RunCommand acCmdRemoveFilterSort Me.FilterOn = False Me.OrderByOn =...
4
by: Aaron | last post by:
Hello all. I am trying to avoid my users from saving filters. The fact is that after they use or change a filter, when closing the form Access would ask: "Do you want to save changes to the...
69
by: DeJuan Jackson | last post by:
Just dropping a quick not for Tom Lane. I sent a personal message today, but I wasn't sure if you'd get it after I remembered all of the spam filters you've got set up. Sorry for the off topic...
6
by: TJO | last post by:
Below is some sample code that fades div tags that is not working in IE 6.0.29 on xp sp2. Can anyone help see why the if(ie5) document.getElementById(divID).filters.alpha.opacity lines are not...
1
by: Dieter Vanderelst | last post by:
Hello, I'm trying to access the Filters-Dll provided by the filters-project (http://filters.sourceforge.net/index.htm). Following the advice I got from the Python list -thank you for that-, I...
5
by: dananrg | last post by:
I would like to learn how to roll my own filter ala early 90's filters like Jive, Fudd, Kraut, Moron, etc, that take text as an input, and re-writes the text adding general hilarity of various...
6
by: smcdonald | last post by:
I have a report that opens up using a pretty complex query. I then pop up a form with combo boxes so the user can apply a filter to the existing report and then refresh the report. I need to export...
0
by: kucol | last post by:
Hi guys, I wanted to ask you for help as I am struggling with it second evening already... I have got tables DEVICES and PARTS. One device can consist of multiple parts. But... I have...
5
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the...
0
by: CatchSandeepVaid | last post by:
We all know that one-to-one associations are non-lazly fetched but during this fetching the filters are not applied. I debugged hibernate code and found that hibernate finally calls...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...
0
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...

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.