[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-03-22
2
Medium Priority
?
189 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?
0
Comment
Question by:MarkZipperer
  • 2
2 Comments
 
LVL 19

Expert Comment

by:dmitryz6
ID: 16262907
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
 
LVL 19

Accepted Solution

by:
dmitryz6 earned 2000 total points
ID: 16262915
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Screencast - Getting to Know the Pipeline

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question