I am creating an SSRS report (on SQL Server 2016) which will generate letters to a set of names in our database. If the recipient of this letter is married (if Spouse in the dataset is not blank), then we need to create an exact copy of the same letter on the following page but using the Spouse's name as the recipient instead.
I used a List control and populated it with the text and the merge fields and it all works great, but now I need to account for spouses.
It seems to me that I would need to use a conditional page break on the List control, which seems straightforward enough, but I am clueless as to how to approach the data fields. In the "Name" area of the letter, I would need the field to pull Recipient on the first page and Spouse on the second IF Recipient is married. Otherwise I need it to pull Recipient only and then move on to the next record without breaking the page.
Any input on how to accomplish this would be most appreciated!
Could you union the spouse data and the primary recipient data into a single dataset and then just process that. This would mean no changes to the report design.
Without seeing your dataset of the dataset query this is a guess but something along the lines of
SELECT PersonID, FirstName, LastName
FROM myTable
UNION
SELECT PersonID, SpouseFisrtName, SpouseLastName
FROM myTable
ORDER BY PersonID
Related
I have a report which uses 3 datasets and on the report a am using Multiple Tables and Textboxes and expressions. When I run the report I have to select a Parameter which in this example is 'City'.
I want a new page for each City (parameter) , I have read to use page breaks and grouping but I selected a List from the toolbox and put that on top of my report, selected 2 'Cities' and expected it to return 2 pages but it returned 49 pages (majority blank)
I want a separate page per city how can I achieve this?
Thanks
If I understand you correctly (it difficult to be sure if you don't post your current design) then you would be better using subreports.
I'm assuming Cities are in a table in your database and each have a unique ID. If you only have the names then you can use CityName inplace of CityID and it will still work.
Create a new report.
Create new dataset (say dsSelectedCities and the set dataset query to something like ...
SELECT CityID, CityName FROM myCitiesTable WHERE CityID IN (#CityParameter)
This will automatically generate a report parameter called #CityParameter. Set the available values etc just the way you did in your original report, so if you need to add another dataset for this then do so. In this example I've assumed labels will be CityName and Values will be CityID. Whatever goes into the Values is what will be passed to our subreport.
Now add a table to you report, it only needs to be one column wide and one row long so just remove any other rows and columns just make sure you leave the detail row and not the header.
Set the dataset for the table to be dsSelectedCities
Make this remaining cell with wide enough to accommodate your subreport (which will be the report you originally wrote).
In the cell, insert a subreport
Set the subreport properties to point to your original report and set the parameter to the CityID field.
This table will act as a loop, for each record found in dsSelectedCities it will give us one row. As each row will have a single CityID we are passing that to the subreport, the subreport in turn just shows one City.
Set the page break option on the details group to break between instances.
You will probably have to modify your original report to accept a single CityID, it depends on how it was designed but hopefully this should get you going.
If this is unclear then post your current report design including all the details about parameters and I'll update the answer.
I am trying to create a report putting a field called contact which has the name of a person. This name is linked directly to another table where I keep all the contacts.
For some strange reason, when I include this name (which in query view displays as the name of the contact), instead of the name appearing, the unique ID number is shown on my report.
As mentioned in the article cited in the above comment, you can use a Combo Box control on your report to do the lookup for you. To see how this can be done, create a new report based on the table containing the lookup field, then drag and drop that field onto the report. That will create a Combo Box control with properties that look something like this:
Row Source: SELECT [Clients].[ID], [Clients].[LastName] FROM Clients;
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
You could use a similar Combo Box control on your actual report to display the client's name rather than their numeric ID value.
Another alternative would be to change the Control Source of the report's Text Box control to have it do a DLookUp() on the table. If the lookup field is named [client] then changing the Control Source of the Text Box to something like
=DLookUp("LastName","Clients","ID=" & [client])
would also work.
I wanted to add to the great answer by Gord:
When using a "web" database (started in Access 2007 I think), you cannot change a report's fields to ComboBox style, nor can you use DLookUp(). (web databases lack a ton of features)
The workaround for this, if you want to create a Web-Report that uses lookup fields, is to create a Web-Query first based on your Web-Table (all the Web-* stuff has a www planet icon over the logo, if you create a new Web-DB in Access 2007+ you'll see what I mean)
So, instead of Table -> Report, you'll have to do W-Table -> W-Query -> W-Report.
Then, the only thing you need to customize to get the data right is the W-Query. Start by trying to reproduce the look in the query to match what you want users to see in the report. Note that here in the query, lookups will work fine (instead of the unique ID's, you get field names like you want). However, this will not carry over to the report. To do that, you gotta get the actual text field name you want into the query:
You should already have one table in your query; start by adding the table that your first lookup field points to. For example, the table I want to print is called Stock_Boards, and it has a lookup field called PCBID_lookup that points to the table Stock_PCBs.
Since you're using lookup fields, there should already be a relationship line between the two tables when you add the second one. If there isn't, something has gone horribly wrong.
Now, see how that line connects two fields on the two different tables? For example, I've got my PCBID_lookup field on my Stock_Boards table, which connects to the ID field on my Stock_PCBs table. If I created a report from this now, PCBID_lookup would be a number, a number that correlates to the ID of a record on Stock_PCBs.
To fix it, I will add the name field I want to show up on the report. In my example, that happens to be a Part Number, rather than the ID. I add the PartNumber field from my Stock_PCBs table to the query, and remove the PCBID_lookup field of the Stock_Boards table from my query.
Since PartNumber is what I want to show up on my report, it effectively replaces the original field (PCBID_lookup)
Repeat for all lookup fields you want in your report.
I had 1 more: I removed the Status field of the Stock_Boards table (which was an ID/Lookup) and added the 'Status' field from the Status table (which was the actual text name)
When finished, your query should look exactly how you want the data to appear, without any special tricks or asking Access to do something unnatural. Save your query, and create a web-report from it. Done!
I'm sure this has been answered somewhere but I don't know how to ask the question such that I can find an answer.
I'm trying to create a form that can allow me to select a person from one table. The table contains SSN, and First, Last, Middle names. I have that part working.
What I don't yet understand how to do is then populate a group of textboxes and labels on the form with the column headers of a second table.
It should populate with everything but the ID and SSN fields and put that person's information (a selection of dates) in the text boxes to be edited.
Sadly, I've already accomplished this in Excel, but due to runtime issues, I'm trying to port it over to Access, since the dataset is getting larger daily, and Excel is no longer well suited for the task.
I don't have enough rep to post an image into this post, so please go here to see a visual representation of what I'm talking about.
Thanks for the help!
For the list of header, you could loop through the RecordSet field name: rst.Fields(n).Name of a Select * query of you table.
You could then use the field selected by the user to build a second query for you last column that match the good user and the right header such has:
StrSql = " Select " & MySelectedField & " From MyTable where userID = " & MySelectedUser &";"
Hope this helps!
I'm trying to make access conditionally only show rows that meet a certain condition, allow me to give you some background info before I proceed :
I've created an Access form and linked it to a test DB on my machine. The particular table I am interested in contains the following (important) rows :
ID , Office, Name, SecurityNumber
The thing is, ID is not unique. There are two Office locations, and each Office has it's own set of unique ID numbers. This means that ID 10 here and there may or may not be the same person. (this data comes out of a legacy security system we're not looking to change yet, so I cannot change it)
But ID -is- unique to each Office.
SO! I created an Access form with TABS! Two tabs, one for each office. What I am trying to achieve now is :
Have the ID/Name/SecurityNumber fields for each tab populate with only rows that match it's particular 'Office' value.
Thank you for reading and thank you for helping! :D
If you want the data for the office locations presented in separate tab page controls, you could use subforms on the pages which differ only in the WHERE clause of the queries used as their record sources. So for the Office1 subform, the query could be:
SELECT ID, Office, [Name], SecurityNumber
FROM YourTable
WHERE Office = 'Office1'
ORDER BY [Name];
Then for Office2, the query would be the same except for the WHERE clause:
WHERE Office = 'Office2'
As I understand your question, that approach would do what you're asking for.
However, that's not really the easy "Access way" to do it. Instead consider a combo box control to allow your users to choose which office they want to view. In the code for the combo's after update event, either modify the SELECT statement used as the form's record source or create a filter expression an apply it.
Also, since you're pulling the form's data from SQL Server, consider whether you want your form to load every record for the selected office location. It may not be much concern if you have only a few to moderate number of rows for each location, but if you'll be dealing with multiple thousands of rows it could be. In general, you should try to avoid pulling copious amounts of data across the wire; pull sparingly instead ... only what you need for the immediate task at hand.
To keep this simple, lets say I have two tables.
The first is called Employees. It contains an id field and an employee_name field.
The second is called Pay. It contains an id field, an employee_id field and an amount field.
Now, I want to run a report on Pay that shows me how much each employee got paid by showing me only the Employee.employee_name and the Pay.amount.
Obviously, I'm going to have to take the employee_id field from the Pay table and match it up with the the id field from Employees, but I have no idea how to do that.
I know a little VBA and am pretty knowledgeable with SQL, but MS Access has me so confused I'm about to kill myself. I hate Access so much, I want to take it outside behind the middle school and get it dead.
This seems like a relatively easy problem, so someone has to know how to do this. Any help would be hugely appreciated.
You are looking for a query like this
SELECT Employees.Id,
Employees.employee_name,
Sum(Pay.amount) AS SumOfamount
FROM Pay INNER JOIN
Employees ON Pay.employee_id = Employees.Id
GROUP BY Employees.Id,
Employees.employee_name;
If you wish to make this as part of a list box, you can either save the sql as a query and set the Listbox property under the Data Tab called RowSource to the Saved Query Name, or you can set the sql string as the RowSource.
Remember to have a look at the Properties called Column Count ( something like 0;3;3 0 being to hide the first column ) and Column Heads (to include column headers, default NO )
If you widh to craete a Report using the data, you can go about this the same way ( Saved Query or Use the Sql String ). The Query/Sql String can be set in the Data Tab in the Record Source property. Now you can add the fields to the report from the Existing Fields window.