Problems with Report Variables - variables

I'm new to SSRS 2012 and have a question about variables. I have a report that retrieves order and order line information from our database (order #, order line #, item, quantity, etc). I need to add a textbox to the footer of the report that can only be displayed for certain items (i.e. if item # equals "123" then show textbox, otherwise hide it.
I added a report variable called 'ItemExists', and unchecked the read-only flag, and set the default value to 0.
I then added an expression to the textbox on the report footer to show it if variable=1, and to hide it if variable=0.
I'm trying to add a textbox with an expression to the body of the report (same group as where the item # is displayed), but I'm unable to get the report variable to update properly. Here's what I tried:
=IIF((Variables!ItemExists.Value = 0) and (Fields!item.Value = "123"), (Variables!ItemExists.SetValue(1)), Nothing)
This works if the value of the item is 123, but if the item is not equal to that value, it still sets the ItemExists variable to 1.
The reason I'm checking to see if the variable is equal to 0 is that there may be multiple lines in the report, and if any one of the items is a match, I want the variable to be set to 1.
I'm not sure if I'm way off track here, but if you could provide any assistance on the best way to achieve this, that would be great.
Thanks in Advance.

Related

How to mimic values in multi page SSRS Report

I need a lab report that has several pages. Each test has a unique reference number and I would like it to appear in the header according to what I have on the page. At the moment I only see one reference number and it remains unchanged after switching to another page. See attached image.
If possible, I would like to get rid of the SampleNo column so that its value is only in the header
The easiest way to do this is to reference the the textbox in your tablix that contains the "Sample No.".
Click the textbox that you have highlighted in the tablix, show the properties window (F4 in Visual Studio - can't remember in Report Builder, I think View/Properties).
Find the Name property of the textbox, this is often the name of the field it contains but not always.
In the example below the textbox name is 'oYear`
Next, set the expression in your header to be something like
=FIRST(ReportItems!oYear.Value)
Change oYear to whatever textbox name in your tablix is.
ReportItems refers to the rendered object name so here we just get the first on each page.
Here the first two pages from a small sample of data which groups by year.

How do I validate a Form input field with a Table row value in microsoft access?

I am having issues with setting a Validation rule in Access.
I have a database with the tables Clients, TypeClient, Sales, SalesList, Items.
I have a form for Sales, with a sub-form SalesList inside which has a relationship with Items in order for me to put several stock items in Sales instead of only one item.
Inside Sales table is ID, Date Sold, ID Client.
Inside SalesList is ID_List(referenced to ID in Sales), ID_Item(referenced to ID in Items), Quantity.
Inside Items is ID, Name, Stock(how much we have in stock), Price
The issue is that I am trying to validate the data I enter in the sub-form Quantity field to be higher than 0, but no higher than the available stock.
The issue is that I have tried using the expression builder to get the value from a calculated query that has 2 fields - the ID and the value for that id, with criteria that is for the ID to get it from the main form, the sub-form, the combo box input and the query works.
But when trying to get it like this:
It shows an error "The expression [Query bla] you entered in the form control's ValidationRule property contains the error The object doesn't contain the Automation object 'Query bla'".
I tried using directly the table Value(but it won't work anyway as it doesn't know for which field to get the stock value from), still the same error. I guess it can't reference to anything else? Normal validation rules work, but I want to validate it not to exceed the value of the available stock for the item I am selling now.
Nowhere on the internet there is a tutorial how to do it with expression builder. How do people validate their fields then?
It doesn't stop me in this case to sell 200 items when I currently have stock of only 2 of them, for example.
Note: I have tried DlookUp in expression builder, straight up tells me No.
Sample wrong validation rule expression builder code:
<=[Query bla]![Stock]
<=[Items]![Stock]
I am currently using VBA and fetch the record I need(the current stock) with one of the following and my unbound text is changing on every subform to the same, it shouldn't happen like that. What can I use to populate a field for each record uniquely:
Private Sub ID_Product_IZBOR_Click()
'Me.Stock_ValueField = DLookup("[Nalichnost]", "Stoka", "[ID]=" & Me.ID_Product_IZBOR)
Me.Stock_ValueField = Me.ID_Product_IZBOR.Column(2)
End Sub
Partial solution: I created a new Dim as Integer and fetched the records based on the ID provided by the field in the form and used BeforeUpdate to validate the current stock. Unfortunately the only way to see the current stock level is to click on the combo box where you choose your product and check the column for that one, it doesn't show anywhere else :(
Don't use the expression builder (I NEVER do) - just type the needed expression in property.
>0 AND <=DLookup("Stock", "Items", "ID=" & [ID_Item])
Another approach is to return Stock in textbox ControlSource then ValidationRule references that textbox. Also, user can then see the quantity limit. Methods of pulling the Stock value from Items table:
include Stock field in Items combobox RowSource - textbox then references column by its index (index begins with 0): =[cbxItems].Column(2); VBA may be needed to Requery combobox after record entry/edit is committed to table.
include Items table in form RecordSource - bind textbox to Stock field (Locked yes and TabStop no)
DLookup() expression in textbox ControlSource
Use ValidationText property to give users a custom message.
However, ValidationRule will not prevent user not entering any value if they skip the control. If you want to make sure a value is entered, either set field as required in table or use form BeforeUpdate event to validate record data.

MS ACCESS: VBA too fast leading to field updating only if Toggle Breakpoint in code, need timer?

I am currently doing a Purchase Order "software" under Access and I am having issue with calculating the amount after a item quantity (qty) update.
When I have Toggle breakpoints in my VBA code on the "after update" event, after updating qty = 5 and going through the lines of code, I have the parent text field correctly updated from the subform one (which is the sum of the 'Total Price' fields).
The code contains a Refresh in order to add the right value rather than the old one:
.
.
However, when I remove the toggle breakpoint, I think that the VBA code does not have enough time fully process the refresh command, which update the parent text field with the wrong (old) value.
This issue leads to have a discrepancy between the actual subform calculated total, and the value added to the parent table (here I removed the toggle breakpoint, and added 1 on the second line item, but the calculation gave a 250 rather than a 251):
When I look at the values in the code, when the breakpoint is on the updating line, you can see that the value of the field is the right one, but the 'watch' field shows the old value:
.
.
Do you guys have a solution to make sure all the fields are updated before going to the next line?
I was thinking using some sort of delay, or an "application wait until processing done" type of command but I cannot find anything that is actually working;
Let me know,
Cheers!
EDIT 1:
The "Expected Total Cost" is bound to a table field called "curPOExpectedTotalCost", which is why I use VBA code to populate the data into its dedicated textbox (called "txtcurPOExpectedTotalCost").
The main goal is simply to have this bound field being correctly updated; I want to be able to change the qty or the unit price and automatically populate the right total PO price into "Expected Total Cost" which is bound to a table; the issue is that it works well when I am running each lines one by one using the breakpoints in my code, but does not work when I remove them; this tells me it is probably too fast, hence a way of delaying the next command or a command to wait for processing to be done.
EDIT 2:
I found a workaround, but it seems overpowered for this simple task I was trying to achieve; good side is that it removes the middle man (the subform textbox that sum all the total prices):
I open a recordset and iterate a variable until I can populate the result into the dedicated "Expected Total Cost" bound textbox:
DoCmd.RunCommand (acCmdRefresh)
Dim RS As DAO.Recordset
Dim SQL As String
SQL = "SELECT numPONumberAndRevID, numPOContentQtyOrdered, numPOContentPrice FROM tblPOSCONTENT WHERE numPONumberAndRevID = " & Nz(Me.Parent.MasterPOID.Value)
Set RS = CurrentDb.OpenRecordset(SQL)
Do While Not RS.EOF
ExpectedCalculatedCost = ExpectedCalculatedCost + RS("numPOContentQtyOrdered") * RS("numPOContentPrice")
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
Me.Parent.txtcurPOExpectedTotalCost.Value = ExpectedCalculatedCost
We could arrange in a simple way.
We name the detail input subform control as sfrmDetail, the main total control can be assigned with a .ControlSource like:
Me.txtcurPOExpectedTotalCost.ControlSource="=[sfrmDetail].[Form].[txtSubFormExpectedTotalCost]"
When txtnumPOContentQtyOrdered updates, your main form changes instanteneously without any VBA code.
In the subform, say sfrmDetail, that will be embedded in the main form as subformcontrol sfrmDetail (yes with the same name), we assign a .ControlSouce=Sum(Qty*UnitPrice) for the control txtSubFormExpectedTotalCost, at the footer of the subform.
Solution II:
As #June7 pointed out in comments, the Total cost, that can be calculated dynamically, should be better only for display only (form input display, report printing, but not saved in disk).
OK, now we want at any cost to stock in field tblMain.curPOExpectedTotalCost the total cost with a slight data redundancy, so in the main form we have Me.txtcurPOExpectedTotalCost.ControlSource="curPOExpectedTotalCost"
In the subform sfrmDetail, we can update with:
Option Compare Database
Option Explicit
Private Sub txtnumPOContentQtyOrdered_AfterUpdate()
Me.Recalc
Me.Parent.txtcurPOExpectedTotalCost.Value = Me.txtSubformExpectedTotalCost.Value
End Sub
Me.Recalc() updates all calculated fields of sfrmDetail before we change the target main table field.
Please consult also Is storing counts of database record redundant? for data redundancy.

Select combobox intem after bounded with SQL Query in Access

I have the following pair of combobox that are used for two inserts in two different access tables from a single form.
The problem I have is that I am not able to make anything else load the form is selected both in Name_OT and in Year the first value that contains corresponding combobox.
I think the solution is with:
Combobox1.Selected (0) = True 'First value
But the combobox goes blank, no text or anything appears.
Solved with this
Cuadro_combinado79 = Cuadro_combinado79.ItemData(0)
Cuadro_combinado85 = Cuadro_combinado85.ItemData(0)

Report ,subreport pentaho

Iam using Pentaho report designer and we want to hide a subreport if there is no data .
I have tried to use this formula :
not(isemptydata())
in the visible expression but it does not seem to work .
So how to hide a subreport if no data .
Pentaho Report Designer elements have "attributes" and "style" sections. In style section there is a field "Visible". If you don't want to make the sub-report visible, it must be set to "false".
When want a function to disable it, the expression must return a "FALSE()" value.
You don't specify how the sub-report is generated and where is it placed (Details, Report Footer, etc), but, I'm gonna assume you have defined a function that has the count of rows for a group "TOTAL_ROWS" (and this is gonna be the field you are gonna compare), so, to hide the sub-report when 0 rows are present:
=IF([TOTAL_ROWS] = 0; FALSE(); TRUE())
"if the total number of rows is zero, return false, else return true".