Print a report Multiple times, (SSRS reporting services) - asp.net

I am currently working on SSRS reports 2008 displaying them in Website created in VS 2010 i.e., ASP.NET 4.0 C#.
My current issue is I have a report with only a Letterhead on it. And this report page needs to be printed multiple times based on the value in number of pages TextBox as shown
To be a bit descriptive: When the user enters the value in Number of Pages TextBox and clicks on this Print button icon, he/she lands on the page with ReportViewer control on it, displaying the report.This report has only a letterhead in the PageHeader of the report and here this report will be printed by clicking the default print button of ReportViewer control. But, I am unable to figure out, how to print this report page as many times as there will be the value in the No of Pages TextBox (as shown in the fig.)
(The Letterhead of the company to be shown in report is retrieved from database through a Stored Procedure)
I tried a lot of Googling but to no avail.

Create a new report.
This report should have 1 parameter called "number of copies" (or equivalent).
It should also have a Tablix with 1 column and no borders, inside the cell insert a sub report pointing to the report with the letterhead.
Your dataset query should be something like this:
WITH dataset AS (
SELECT 1 AS ID UNION ALL
SELECT ID + 1 FROM dataset WHERE ID < #Param
)
SELECT ID
FROM dataset --edit: obviously I was missing the table
OPTION (MAXRECURSION 0)
Then on your tablix, use this dataset, group by ID and on the group properties select "Page Breaks"->"Between each instance of a group".
If I understood your question correctly, this should do the trick.

Expanding on Joao's solution (thanks for that) you can also do it without a subreport by joining the counter table to the actual data you want to display in the dataset.
Add a Copies integer parameter with a default value of 1
Update your dataset to include the counter and join
-- Generate a table with #Count rows
WITH dataset AS (SELECT 1 AS Copy UNION ALL SELECT Copy + 1 AS Expr1 FROM dataset AS dataset_2 WHERE (Copy < #Copies))
SELECT * FROM dataset INNER JOIN (
-- The primary data to repeat
SELECT * FROM MyTable WHERE Id = #IdParam
-- End
) d ON 1=1 OPTION (MAXRECURSION 0)
Add/update your row group to group on [Copy]
Set the row group page breaks to 'between each instance'

Related

Returning Count of 0 for Record summaries with 0 sub-records

I am using crystal reports XI. I am working with a SQL database that was created before I got here, and I can't make changes to the tables or link structure. There are 4 tables in the database that I need for this report.
Table 1 - Companies || Fields: CompanyIDPK, CompanyName, YearActiveIDFK
Table 2 - ActiveYears || Fields: YearActiveIDPK, YearNameIDFK
Table 3 - YearNames || Fields: YearNameIDPK, YearName
Table 4 - CompanyOrders || Fields: OrderIDPK, CompanyIDFK, YearNameIDFK, OrderNumber, OrderCost
I want to create a report that is grouped by Year and by Company. I want each company to show the number of orders within each year, including showing 0 if there were no orders that year.
I can get the report to show all the companies that were in a given year, but as soon as I try to start showing a count, it only shows companies that had at least one order.
Thanks for any help!!!
My guess is that this is happening because Crystal only adds tables to your SQL query after you've added them to the designer. This happens even if you have linked your tables in the database expert.
I'm assuming you have the default join type of INNER JOIN. What's probably happening is as soon as you add your Count Summary on one of the fields in CompanyOrders, Crystal is adding it to your SQL Query.
The reason this causes a problem is because an inner join only returns records if the linked fields are in both tables. If companies haven't placed an order in the last year, they won't have any records in the CompanyOrders table. This means your SQL Query won't return any records for those companies, because those companies need to be in both tables for records to be returned.
The solution for this is to change the join type from INNER JOIN to LEFT OUTER JOIN. This can be accomplished by going into the Database Expert (Menu > Database > Database Expert), clicking the Links tab, double clicking the line that goes from your Companies to your CompanyOrders table, and selecting the Left Outer Join Radio button.
Now all of the Companies will show up, but since some don't have records in the CompanyOrders table, the count for the orders will be 0.
Let me know if this was your problem.
ZMcK
You didn't say that you couldn't create database objects, so if it is possible I would create a view or stored procedure in the SQL Server database to return the data you require in the format you want and take Crystal Reports out of the equation in terms of linking tables.

How to set variable query count result in visual foxpro 7

I am new in Visual FoxPro.
I want to count rows by some id and print it in the report.
Where I should place this query and how to set it to variable?
If you want it at the top of the report, before it has iterated through all the data, you need to pre-calculate it.
select mytable
sum myvalue for id="ABC" to gnTotal
report form myreport to printer preview
In this scenario gnTotal will be visible to the report and you can just use it in a report expression.
If you want it in the summary band or you want subtotals by group you would use a report variable of type 'sum'. The expression for the variable would then be:
iif(id="ABC", mytable.myvalue, 0)
In other words if for a particular record the value of id is "ABC" then add myvalue to the sum, otherwise add zero.
Then use the report variable in an expression at the bottom of the report.

MS Access 2010 Triggers/data macros

I am developing a database to do a annual inventory count with 32 tables in it, 33 including the Master.
We currently have 4000 SKU's so the master table needed to be broken down into smaller tables so I can hand out a realistic amount of work to my counters.
What I am trying to achive is when my counters enter data in the smaller tables using the UI it would automatically populate the fields in the master table.
Any help would be greatly appreciated.
Michael
In Access, there is no way to apply a trigger to a table. What you can do is create a form that implements a grid. Have an After-Update event fire that does what you need. You can make the form look like a table by using the datasheet view.
While you can create a data macro* to update a table from an update on another, why would you want to do it in this case? You can either include the quantity field in the sub table and validate the data against the main table before running an update query, or the sub table (note, table, the employee ID will be sufficient to divide the data) could consist only of an employee id and an SKU, the sub table can then be joined to the main table by SKU and all updates use the quantity field from the main table:
SELECT Mytable1.SKU, MyTable.Quantity
FROM MyTable1
INNER JOIN MyTable
ON MyTable1.SKU = MyTable.SKU
WHERE EmployeeID = [Enter ID: ]
*Data Macro

Ms Access AddItem with VBA

I have a Form that has a button on it. The button basically copies records from one Table to the other.
As records are read and copied, it is also checked for specific values. E.g. If one of the fields in the table has a value of "" then it should call another form that allows me to enter a date. Once the date is entered and the form is closed the programme carries on with copying.
It can also happen that the key fields in the table that is being copied are duplicate. In this case I should a 'listbox form' should be launched with a listbox displaying the values of the duplicate records. I should then select the correct record that I need copied.
Dim NumberCount As Long
NumberCount = RecordsetElementValue.RecordCount
If NumberCount > 1 Then
With Form_F_ListBox.List30
RecordsetElementValue.MoveFirst
Do
With Forms!F_ListBox.List30.AddItem(RecordsetElementValue!E_ElementValue)
End With
RecordsetElementValue.MoveNext
Loop Until RecordsetElementValue.EOF = True
DoCmd.OpenForm "F_ListBox", acNormal
End With
End If
The code sample above is what I have for in case there are duplicate records (NumberCount > 1)
The listbox in my F_ListBox form should be filled with the values in my recordset.
I now run into a runtime error 6014. The RowSourceType property must be set to 'Value List' to use this method.
What am I doing wrong?
The usual way to set the row source of a combo or list box in MS Access is to use an SQL statement, however, you can also use a list. This is controlled by the row source type.
Me.MylistBox.RowSourceType = "Value List"
From your notes, it seems that an SQL statement for the row source would be easier:
Me.MylistBox.RowSource = "SELECT ID FROM MyTable"

How do I select a column with the latest "datetime" data type?

How do I select a column with the latest "datetime" data type, in Visual Web Developer 2008, ASP.NET 3.5 ?
In the config data source dialog my WHERE options are greater than cookie, control, etc... but I would like to select where the datetime is the latest in the table.
(Select row from table where datetime is last updated....)
Thank You.
EDIT -
This will be for a specific user in the table, i.e.
Select row in table from specific current userid WHERE the row was his latest updated entry.
or you could use the MAX function like that:
SELECT * FROM myTable WHERE User='Me' AND DateColumn=(SELECT MAX(DateColumn) from myTable WHERE User='Me')
The previous solution works perfectly though but this one can be useful for more complicated cases I think.
Could you select top 1 and sort by the column descending e.g.
select top 1 ...
from MyTable
where User = #theUser
order by DateColumn desc
edit-- added in the where clause for user
that should get you a single row with the latest date from the table...i'massuming this table gets something written to it each time a user does 'something'...so you can grab what they last did...

Resources