Access filters on splitform through query to report - sql

I have a splitform and what I want to do is open report on filter I use in this spltiform. What's important is that in this splitform you can do the correction of the row (you can't edit the previous row, but it creates two additional rows - one is negative and the other is to edit and I have one column which stores the ID of corrected row - CorrectedRowID). So I can't create report based on that table, so I created a query which groups this data by CorrectedRowID and it takes the last row of each ID so I have only the newest row of every ID. Then based on that query I created report.
On the splitform I have button which opens the report. But what I want is that when I have filter in this splitform and I click on the button Open Form it opens the report already on the filters. I have used this code in this button in VBA:
Private Sub Command282_Click()
DoCmd.OpenReport "tb_ewid_WNT1_raport", acViewPreview, , Me.filter
End Sub
When I create a normal report (not based on query) filter works great, but when I put some filter on the data in this splitform on one column it asks me for the value of the column on which I want to filter my data.
The query returns the newest rows of each ID. For example:
ID
Name
Quantity
Price
CorrectedRowID
IsCorrection
1
bread
4
1,5
1
No
2
milk
3
2,3
2
No
3
bread
-4
1,5
1
Yes
4
bread
11
1,5
1
Yes
In this case query will return this, so for each CorrectedRowID it returns the highest ID:
ID
Name
Quantity
Price
CorrectedRowID
IsCorrection
2
milk
3
2,3
2
No
4
bread
11
1,5
1
Yes
I created the report based on this query. And I also created a button on splitform which uses the code I wrote up. When I filter my data and when I click on this button it asks me for the value for some column (it's not the same every time). The values that it asks for are combo boxes which take the values from not the same table. The query uses JOIN.
Where did I make mistake?

Related

Limit number of script triggers by field

I am trying to figure out how to limit the number of times an ID can be selected.
I have a list of mentors, some who can be selected 1 time and others who can be selected 2 times. I am using a button that performs a Set Field script. When the button is clicked the ID value is copied to another list. It remains in the original list but also is shown in another. I want to say something like:
If field "mentor count" = 2 then You can select 2 times, else you can select 1 time.
I have no idea how to go about it.
Do you have any suggestions please?
There are a total of 3 lists. One is mentors, 1 is students and the other is both. The user selects a mentor and student to match up. Each row in this table is a new match.
I tried conditional action which failed. I am thinking I will need a script.

Edit of Row in Access

I have table which looks like this:
ID
NameOfProduct
Quantity
Price1 in USD
Price 2 in USD
1
Energy
5
3,5
2,7
2
Gas
10
3
21,2
Then I created form based on this table, which is a Splitform. I want to create a button which would allow me to create a correction of chosen row.
It should create another row with negative values of the corrected row (only the columns which are numeric), because I don't want to erase the row, I need the evidence for later how the original row looked like and then it would allow me to edit values of selected row and add it into the table as another row
I have no idea how to even start with this - If I can do this by only using macros, or SQL or do I need to use VBA?
Please help!

Choosing which rows to sum and average in either SSRS or SQL

ROW column 1 column 2
1 A 1
2 A 1
3 A 3
4 A 1
5 A 2
6 B 1
7 B 3
8 B 1
Pic of table
Lets say I have this table as shown above. I want to be able to average SELECTED values from column 2. Am I able to use any function in SSRS that allows me to select which value to use to average? The end goal is to allow the user to interactively choose which value to average.
For example if I would want to use ("Row 1 + Row 2 + Row 4")/3, or (Row 6 + Row 8)/2, how can I go about letting the end user to choose those values to average?
Is there something that I need to do in SQL first to make it easier in SSRS?
The idea is by using report parameter and dataset filter
Add parameter in SSRS to allow user input of multiple values, set the available values for row-1, row-2, and so on
here for your reference how to add the parameter in SSRS
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-change-or-delete-a-report-parameter-report-builder-and-ssrs?view=sql-server-ver15#:~:text=To%20add%20or%20edit%20a,or%20accept%20the%20default%20name.
after you add the parameter, let's say you already have a dataset which is SQL query such as:
SELECT *
FROM the_table
Right click on your dataset, on properties, in the filter tab, add a filter for the column ROW IN parameter that you have made earlier
after you add filter on your dataset, on your report, simply use that dataset and put expression AVG(Column 2)

How to combine a row of cells in VBA if certain column values are the same

I have a database where all of the input from the user (through a userform) gets stored. In the database, each column is a different category for the type of data (ex. date, shift, quantity, etc) and the data from the userform input gets put into its corresponding category. For some of the data, all the data is the same except for the quantity. I was wondering how I could combine these rows into one and add the quantities to each other for the whole database (ex. combining the first and third data entries). I have tried playing around with a couple different loops but can't seem to figure anything out.
Period Date Line Shift Type Quantity
4 x 2 4/3/18 A 3 14 18
4 x 2 4/3/18 A 3 13 12
4 x 2 4/3/18 A 3 14 15
Thank you!
If you're looking to modify the underlying database, you might be able to query the data into the format you want by including all the other columns in a GROUP BY statement, save the result to another table, then replace the original table with the properly formatted one.
If you have the data in Excel and you just want to view it with the duplicate rows summed, a Pivot Table would be a good choice. You can select all the other columns as rows for the Pivot Table and sum of Quantity as the values.

ssrs report : Facing issues with Master detail kind of report

I need to generate a report of below format. The header repeats only per page.
ItemNr | ItemGenDesc | FulfilmentBin | onHand
-----------------------------------------------
CAP100 Capacitor FulFil1 5
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT2 100 1 5
2 bkBUSLOT3 150 2 6
CAP400 Transistor FulFil12 20
CAP500 Transistor FulFil14 30
binPriority | binBackup | binBackupQty | binMin | binMax
-----------------------------------------------------------------
1 bkBUSLOT5 250 5 9
My SQL output is as below
I tried to work with 2 tablix and somehow I got the output coming up in preview mode but when I export to PDF, I get blank lines between each item. I am guessing that's because the binPriority grid (detail grid) is hidden when the itemnr count <=1. Also the tablix1 row header appears for every grouping but I want row header to appear once per page.
Can anyone suggest what are the ways to generate this type of report?
Thanks.
Update 1 : Sorry CAP500 in the report should be Radiator. My typo mistake. The report should be grouped by ItemNumber and it is sorted by binPriority. So it will print binpriority=0 in the master grid and then in the detail grid it will print in the order of binPriority. The OnHand that is shown in the master grid is relevant to binPriority= 0.
You can achieve your specified layout with a single Tablix. This is fairly simple if you don't mind Columns 2-4 in your Group heading lining up with Columns 1-3 in your Detail. Since horizontal page real estate isn't really an issue (only 6 columns counting the blank column to the left of your Detail columns), I would take this route.
I'm not sure how much you know about SSRS, so forgive me if this explanation is too rudimentary. Others with less experience than you might find it helpful as well.
Right Click the Detail Row on your Tablix.
Select Add Group => Row Group => Parent Group.
Set the Group By value to ItemNumber and check the "Add Group Header" box.
This creates a Group By Column, which I would delete for your specified layout. Make sure to only delete the Column, not the Row Group.
In the Grouping Window (down at the bottom by default), right click the ItemNumber Row Group and select Group Properties.
On the Sorting tab/menu, set the Sort By value to binPriority.
Right Click your new Row Group Row on the Tablix and select Insert Row => Inside Group Above. You'll need to do this twice so you have 3 Row headings in the Row Group.
Insert 3 more columns for a total of 6 columns in your Tablix.
Put your ItemNr, ItemGenDesc, FulfilmentBin, onHand Labels and Values in the first two Rows, first 4 Columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Labels in the Last Row, Last 5 columns of your Row Group.
Put your binPriority, binBackup, binBackupQty, binMin, binMax Values in the Last 5 columns of your Detail Row.