PC Review


Reply
Thread Tools Rate Thread

Help with Filter & FilterON

 
 
EAB1977
Guest
Posts: n/a
 
      25th Sep 2008
Can anyone tell me why this code is not working? It opens the report
fine but does not enforce the filters.

Private Sub btnCost_Click()
DoCmd.OpenReport "rptCost", acViewPreview
Reports("rptCost").Filter = Me.lstResults.Column(0)
Reports("rptCost").FilterOn = True
End Sub

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      25th Sep 2008
"EAB1977" <(E-Mail Removed)> wrote in message
news:700fa171-02cd-49af-b1aa-(E-Mail Removed)...
> Can anyone tell me why this code is not working? It opens the report
> fine but does not enforce the filters.
>
> Private Sub btnCost_Click()
> DoCmd.OpenReport "rptCost", acViewPreview
> Reports("rptCost").Filter = Me.lstResults.Column(0)
> Reports("rptCost").FilterOn = True
> End Sub
>



I'm not sure what's wrong -- what is the value of lstResults.Column(0) ?

I would normally do this via the Where-Condition argument of the OpenReport
method:

DoCmd.OpenReport "rptCost", acViewPreview, _
WhereCondition:=Me.lstResults.Column(0)

But either way, Me.lstResults.Column(0) must evaluate to a valid
where-condition.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      25th Sep 2008
On Thu, 25 Sep 2008 13:41:02 -0700 (PDT), EAB1977 <(E-Mail Removed)> wrote:

>Can anyone tell me why this code is not working? It opens the report
>fine but does not enforce the filters.
>
>Private Sub btnCost_Click()
> DoCmd.OpenReport "rptCost", acViewPreview
> Reports("rptCost").Filter = Me.lstResults.Column(0)
> Reports("rptCost").FilterOn = True
>End Sub


You're opening the report unfiltered, displaying the unfiltered result, and
THEN setting the filters. Try passing the filter arguments in the OpenReport
method instead. Note that the filter must be a valid SQL WHERE clause, with a
fieldname and a value (e.g. "[CompanyID] = 3145"); unless your listbox
contains such strings it's not going to work.

Try something like

DoCmd.OpenReport "rptCost", acViewPreview, WhereCondition := "[fieldname] = "
& Me!lstResults.Column(0)

and leave the Filter properties alone.
--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to change .Filter or .FilterOn Steve Microsoft Access 0 11th Dec 2009 08:34 PM
Setting Filter and FilterOn properties of a report from code. Stephen @ ZennHAUS Microsoft Access Reports 3 26th Apr 2009 03:23 AM
Help with Filter and FilterOn EAB1977 Microsoft Excel Programming 2 25th Sep 2008 09:38 PM
Using Subform's Filter & FilterOn Propety from the Main Form =?Utf-8?B?QW1lcnk=?= Microsoft Access Form Coding 1 18th Aug 2006 02:14 AM
filter and filteron for reports =?Utf-8?B?RGFuaWVs?= Microsoft Access VBA Modules 1 28th Jun 2006 02:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:20 PM.