change report recordsource depending on form recordsource

emcf

Member
Local time
Today, 22:07
Joined
Nov 14, 2002
Messages
209
afternoon all,

I have a form that runs off a main query. This query brings thru info to do with several departments in my company. I have added buttons that allow the user to narrow down the records shown to a specific department (by using me.recordsource ="QryXdept" on the 'on click' event). this works absolutely fine (thanks to a post from paddyirishman i found on a search:) ).
what i am now trying to do is to do the same for reports generated from the form. how would i get the report to look at the current recordsource and use that query to base the report on?? i would also like to have a VB warning box, however that is within my capabilities (i think!).

thanks in advance for your time.
 
You can easily base a report on a form's recordsource by using this code:
DoCmd.OpenReport method. The syntax of the method is:
DoCmd.OpenReport reportname, View, FilterName, WhereCondition

Try using some code like this (attached to the click event of a command button) to open the report filtered for the same records as your form:
DoCmd.OpenReport reportname, acViewPreview, Me.Filter
 
You can easily base a report on a form's recordsource by using this code:
DoCmd.OpenReport method. The syntax of the method is:
DoCmd.OpenReport reportname, View, FilterName, WhereCondition

Try using some code like this (attached to the click event of a command button) to open the report filtered for the same records as your form:
DoCmd.OpenReport reportname, acViewPreview, Me.Filter

Hi, I googled this solution and tried implimenting it myself with the following code:
Code:
DoCmd.OpenReport rptFindExibit, acViewPreview, Me.Filter

and got the following error message

'The action or method requires a Report Name argument'
 
Right it's looking like I do need help with this.

My report is based on the query qryResultsAll

I need it to be filtered by the recordsource on the form. This might not necessarily be based on the same query but the data fields displayed will all be identical. I tried the code
Code:
DoCmd.OpenReport rptFindExibit, acViewPreview, Me.Filter

However it goes ahead and prints out the entire results of qryResultsAll, not filtering it by what is displayed on the form.

Any idea why not?
 
Further development.
I realised it's the subform with the recordsource, not the main form. So I tried to following:

Code:
DoCmd.OpenReport rptFindExibit, acViewPreview, Me.SFItem.Form.Filter

It still works, but it still prints all 91 pages of the entire query, unfiltered. *scratches head*
 

Users who are viewing this thread

Back
Top Bottom