PC Review


Reply
Thread Tools Rate Thread

Acc2010 - Filtering Report based on Subform Filter

 
 
vvariety
Guest
Posts: n/a
 
      19th Jan 2011
I have been trying to filter a report based on the results of a filter
on a form. The print button on the form has the following code:

Dim stWhere As String

stWhere = Forms![frmlibraryMenu]![frmBookListing].Form.Filter

DoCmd.OpenReport "rptbooklisting", acViewPreview, stWhere

Issue: If there is no filter then the report previews all 1500+ pages
fine if the form is filtered then the report comes up blank with an
error msg. SubformName.fieldName "*Gold*"

Can't figure out what I am doing wrong any help would greatly be
appreciated.
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      19th Jan 2011
StWhere should be a string that contains the name of a field, an operator, and
a value to be searched for.

Try debug print and see if you get something like the following returned.
Debug.Print stWhere

In the VBA immediate window you should see the string that is in stWhere

MyField Like "*Gold*"
where myField is the name of a field in the report.


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 1/19/2011 10:42 AM, vvariety wrote:
> I have been trying to filter a report based on the results of a filter
> on a form. The print button on the form has the following code:
>
> Dim stWhere As String
>
> stWhere = Forms![frmlibraryMenu]![frmBookListing].Form.Filter
>
> DoCmd.OpenReport "rptbooklisting", acViewPreview, stWhere
>
> Issue: If there is no filter then the report previews all 1500+ pages
> fine if the form is filtered then the report comes up blank with an
> error msg. SubformName.fieldName "*Gold*"
>
> Can't figure out what I am doing wrong any help would greatly be
> appreciated.

 
Reply With Quote
 
vvariety
Guest
Posts: n/a
 
      19th Jan 2011
On Jan 19, 2:28*pm, John Spencer <JSPEN...@Hilltop.umbc> wrote:
> StWhere should be a string that contains the name of a field, an operator, and
> a value to be searched for.
>
> Try debug print and see if you get something like the following returned.
> Debug.Print stWhere
>
> In the VBA immediate window you should see the string that is in stWhere
>
> * *MyField Like "*Gold*"
> where myField is the name of a field in the report.
>
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
>
> On 1/19/2011 10:42 AM, vvariety wrote:
>
>
>
> > I have been trying to filter a report based on the results of a filter
> > on a form. The print button on the form has the following code:

>
> > Dim stWhere As String

>
> > stWhere = Forms![frmlibraryMenu]![frmBookListing].Form.Filter

>
> > DoCmd.OpenReport "rptbooklisting", acViewPreview, stWhere

>
> > Issue: *If there is no filter then the report previews all 1500+ pages
> > fine if the form is filtered then the report comes up blank with an
> > error msg. *SubformName.fieldName "*Gold*"

>
> > Can't figure out what I am doing wrong any help would greatly be
> > appreciated.- Hide quoted text -

>
> - Show quoted text -


The results of the debug window is
debug.Print stwhere
([frmBookListing].[Title] Like "*Roc*")
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      20th Jan 2011
That should probably be
Title Like "*Roc*"

That assumes that the report has a field named Title in its record source.

The "frmBookListing" part refers to the FORM which the report's record source
would have no idea about.

If the filter string is never more complex than this example you could try
parsing the filter to remove the reference to the subformName

stWhere = Forms![frmlibraryMenu]![frmBookListing].Form.Filter
stWhere = Mid(stWhere,Instr(1,stWhere,"].")+2)


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 1/19/2011 4:34 PM, vvariety wrote:
> On Jan 19, 2:28 pm, John Spencer<JSPEN...@Hilltop.umbc> wrote:
>> StWhere should be a string that contains the name of a field, an operator, and
>> a value to be searched for.
>>
>> Try debug print and see if you get something like the following returned.
>> Debug.Print stWhere
>>
>> In the VBA immediate window you should see the string that is in stWhere
>>
>> MyField Like "*Gold*"
>> where myField is the name of a field in the report.
>>
>> John Spencer
>> Access MVP 2002-2005, 2007-2010
>> The Hilltop Institute
>> University of Maryland Baltimore County
>>
>> On 1/19/2011 10:42 AM, vvariety wrote:
>>
>>
>>
>>> I have been trying to filter a report based on the results of a filter
>>> on a form. The print button on the form has the following code:

>>
>>> Dim stWhere As String

>>
>>> stWhere = Forms![frmlibraryMenu]![frmBookListing].Form.Filter

>>
>>> DoCmd.OpenReport "rptbooklisting", acViewPreview, stWhere

>>
>>> Issue: If there is no filter then the report previews all 1500+ pages
>>> fine if the form is filtered then the report comes up blank with an
>>> error msg. SubformName.fieldName "*Gold*"

>>
>>> Can't figure out what I am doing wrong any help would greatly be
>>> appreciated.- Hide quoted text -

>>
>> - Show quoted text -

>
> The results of the debug window is
> debug.Print stwhere
> ([frmBookListing].[Title] Like "*Roc*")

 
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
filtering report based on subform control =?Utf-8?B?VFhsaWxiaXQ=?= Microsoft Access Reports 1 9th Nov 2006 02:35 PM
Filter the main form based on a subform filter bjc3@spinfinder.com Microsoft Access 3 17th Oct 2006 05:43 PM
subform combo to filter based on other subform...technically mainform's other subform records. nospam@thankyou.com Microsoft Access 0 15th Sep 2006 07:51 PM
Filter/requery a subform based on active record of another subform =?Utf-8?B?dGZvc3N1bQ==?= Microsoft Access Getting Started 1 10th Feb 2005 07:34 PM
Filtering based on a filter James Microsoft Excel Misc 2 26th Jan 2004 09:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:30 PM.