We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Run a formatted report with seperate queries by creating seperate command buttons

MarkZipperer
MarkZipperer asked
on
Medium Priority
208 Views
Last Modified: 2010-04-17
I want to have an Access form from which I can run a report (Report1) using Query1 which will filter for all of the records created in a given year (for instance) by hitting CommandButton1 and then have another Command Button (CommandButton2) run Report1 with Query2 which will list all of the records sorted in Ascending date order and so forth.  In effect, I want to eliminate the need to have several copies of the same report which need to be update every time the format of the report needs to change.  
How do I select the query with code of the command button rather than in the Record Source on properties page of the report while in design view?
Comment
Watch Question

Top Expert 2005

Commented:
Use open argument

On first button
DoCmd.OpenReport "Report1", acViewPreview, , , , "Q1"

On first button
DoCmd.OpenReport "Report1", acViewPreview, , , , "Q2"


On report open event
if me.OpenArgs="Q1" then
   me.RecordSource="Select * from Query1"
else
  me.RecordSource="Select * from Query2"
end if
Top Expert 2005
Commented:
typo
Use open argument

On first button
DoCmd.OpenReport "Report1", acViewPreview, , , , "Q1"

On second button
DoCmd.OpenReport "Report1", acViewPreview, , , , "Q2"


On report open event
if me.OpenArgs="Q1" then
   me.RecordSource="Select * from Query1"
else
  me.RecordSource="Select * from Query2"
end if

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.