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

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?
MarkZippererAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dmitryz6Commented:
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
0
dmitryz6Commented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.