Solved

Trying to verify Filter syntax for Access form.

Posted on 2012-03-13
10
321 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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
 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

813 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

15 Experts available now in Live!

Get 1:1 Help Now