Solved

Trying to verify Filter syntax for Access form.

Posted on 2012-03-13
10
320 Views
Last Modified: 2012-03-13
Just wanted to see if someone could have a quick look at my syntax I'm using on my filter for my form. It's based off of information on another form which is currently open with data populated. (I used to have the criteria in a query but wanted to move the criteria into the forms filter instead).

Here is the syntax I tried;

[LineItemMonth] = Eval('[Forms]![frmOperatingPlan]![cboMonth]') and [LineItemYear] = Eval('[Forms]![frmOperatingPlan]![txtYear]')

Maybe I need to do some kind of refresh or requery on the form assuming the syntax is correct?

Thanks!
0
Comment
Question by:SeyerIT
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 230 total points
ID: 37715901
I would have gone for..

[LineItemMonth] = Eval("'" & [Forms]![frmOperatingPlan]![cboMonth] & "'") and [LineItemYear] = Eval("'" & [Forms]![frmOperatingPlan]![txtYear] & "'")

but I'm not 100% confident...
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 230 total points
ID: 37715903
What you posted is not technically a "Filter".
All you are doing there is assigning some values to a field/control...

It is also not clear if this is in a controlsource or in VBA

First do something like this on a button to even see if the value is what you want
msgbox Eval('[Forms]![frmOperatingPlan]![cboMonth]') and [LineItemYear] = Eval('[Forms]![frmOperatingPlan]![txtYear]')

A Filter in Access will typically look Like this:
"SomeField=" & SomeValue
(For a numeric filter value)
ex: "EmployeeID=" & me.SelectedEmployeeID

or like this for a string filter value:
"SomeField=" & "'" & SomeValue & "'"
ex: "State=" & "'" & me.StateName & "'"
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37716177
Boag, I tried puttin the code you provided in an on click event to a button on the form and I got a Compile error.. It's highlighting the; msgbox Eval('[Forms]![frmOperatingPlan]![cboMonth]') and [LineItemYear] = Eval('[Forms]![frmOperatingPlan]![txtYear]') (first tick mark)

I have managed to put together something that works based on some syntax you both provided. (I also removed the Eval from this.. Doesn't appear to have been necessary for filtering. I only originally had it on there when I was using it in criteria for the query)


So here goes;

On the OnLoad event for the form I placed the following code;

Private Sub Form_Load()


Me.Filter = "[LineItemMonth] = " & "'" & [Forms]![frmOperatingPlan]![cboMonth] & "'" & " and " & "[LineItemYear] = " & [Forms]![frmOperatingPlan]![txtYear]
Me.FilterOn = True


End Sub


It took me a while to get the syntax just right but it did the trick. I'm guessing I could just apply this to the just the form itself without even needing to put this all in vba but it worked pretty good.. Besides, doing this maybe I can put an if statement in that will filter based on which date form is open that it is reading from.

Thanks for both of yours' help!
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37716235
Just for fun, can you try it like this:

Me.Filter = "[LineItemMonth] = " & [Forms]![frmOperatingPlan]![cboMonth] & " and " & "[LineItemYear] = " & [Forms]![frmOperatingPlan]![txtYear]
Me.FilterOn = True
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37716475
No problem;

I get a "Enter Parameter Value" box for the month I just ran..

parm
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37716529
OK then, never mind...

I was just curious...
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37716531
No problem Boag..

Thanks again for the help!
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 40 total points
ID: 37716664
Fancy Filters formSee my Fancy Filters sample database for syntax examples for creating filters based on values of various data types selected from textboxes and combo boxes on a form:

http://www.helenfeddema.com/Files/accarch129.zip
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 37716676
If you are getting the Parameter Value pop-up, that is because there is a parameter on a query, which should be removed.
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37716715
Thanks for the information Helen. I will definitely put that to good use. I already got managed to resolve this problem though. We were just experimenting when we got the Parameter pop-up
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now