Multi Record Validation in Oracle Forms - sql

Form Field
I wanted to apply validation on Plan Ratio field if user entered ratio exceed 100 then show error how can I do in when validate trigger as plan ratio is the same field but have different records

You can setup an invisible Calculated Item, that sums up Plan ratio field, name it for instance as SUMMARY_FIELD and then add WHEN-VALIDATE-ITEM trigger for each Plan ratio item of the records like this:
BEGIN
IF :SUMMARY_FIELD>100 THEN
message('nok'); --or whatever alert you like
RAISE Form_Trigger_Failure;
END IF;
END;
PS. How to create Calculated Item:
To create a calculated item:
1. In the Object Navigator, create a new interface item (make sure it is a control item).
Tip: The item's datatype must be compatible with the calculation you wish to use to
compute the item's value. For example, if you wish to compute an item's value with the
Sum function, create an interface item of datatype Number.
2. Double-click the item's object icon to display the Property Palette.
3. Under the Calculation node, set the item's Calculation Mode property to Formula or
Summary.
4. If you set Calculation Mode to:
Formula, click on the Formula property, click the More button to display the Formula
dialog, and type a PL/SQL expression to define the formula. Click OK to compile the
expression.
Summary, use the Summary Function popList to select a summary type, then use the
Summarized Block and Summarized Item popLists to select the block and item whose
values will be summarized to compute a value for the calculated item.

Related

Oracle Apex List of values selection and button disable upon repetition of same selection

I have an interactive report with two regions.
The first region is static region with a select list and a button to submit the process.
The second region is the report region which refreshes the region based on first region select list value and Process (calculate) button submitted.
However if I try to submit same item (List of values) subsequently the process button must be disabled. (i.e) Any repetition of same List of values, once calculation or process is performed, the calculate button must be disabled and these are all based on input selection from front end.
Please note there is not any direct relationship between the Select list button (Page item) and second region columns and I cannot achieve it by distinguishing at database level if it is processed or unprocessed, as there is not any column maintained in database tables (in this case second region about year which is processed).
How can process be disabled second time?
and only if select list for quarter is entered for first time the process button (Calculate) must be enabled based on.
The second region values are populated/refreshed by swapping the columns this_year_q1 to last_year_q1, last_year_q1 to year_before_last_year_q1 etc., if calculate button is enabled and process is called.
So in below case, the calculate button is enabled when select list is (Quarter is Q4:01/10/2017 to 31/12/2017), this is fine and must allow process for first time.
Subsequent reselection of same value must not allow process to calculate.
1:
Here's an idea:
create a (hidden) page text item
using a dynamic action on a button
compare current Select List item's value with hidden item's value (don't forget the NVL function!)
if they don't match, put current (selected) Select List item value into the hidden item so that you could check it when the button is pressed once again (i.e. whether user selected the same value or not) and submit
if they match, do nothing (don't submit)
If you don't want to run the report twice not only for subsequent executions but during the session, you'd have to store selected values somewhere (a table?). The rest would be the same - you'd only have to select from that table and compare Select List's values with values already used.

MS Access: Reset input field in form to default value 0 upon exit form

EDIT: The fields shown in pictures below all have "value list" as row source type. The input in these fields are used in queries that pull data from tables as well, but these fields themselves do not use any tables.
I have a form in Access that requires users to provide input via listboxes, and then queries use that data to perform calculations.
However,when the entire access file is closed, the same input values are still in the listbox after reopening.
Ideally I want the values in the input fields to default to 0 (not null) as soon as the access file is closed (or re-opened), so when the user opens the database, he will see the value "0" in those fields. The reason to why I want the value 0 as default is because the inputboxes reflect possible commodities a product can contain, and I want to allow users to define the % commodity a product does or does not contain. 0 means the product does not contain that commodity and the user does not have to change the value in the listbox (more user friendly in my opinion). Picture illustration:
Hence each time I re-open the access file, I keep seeing those input values above, while I want them to be 0.
I did some research but don't really understand how to use the expression builder, and I can't find a way to make it work via a macro. I read something about the listboxes having to be 'bound', but I'm not entirely sure how to deal with this.
This is the above listboxes in design view:
You are using listboxes but at a height of one selection which is not the optimal use for such a form control as no multiple listing is shown at once together.
Consider using free-form textboxes with a default value of zero. But if you need to control a user's input, use combo boxes which defaults to the zero selection item. Most likely right now, each listbox is defaulting to its first selection item.
Here is how the Property Sheet / Data Tab of the combox would look (in fact Default Value might be redundant as zero is the first item):
Row Source : 0;20;40;60
Row Source Type: Value List
...
Default Value : 0
If combo boxes use a table/query row source, you will need to append a value of zero with a UNION query:
Row Source : SELECT TOP 1 0 AS ColName FROM TableName UNION SELECT Val FROM TableName;
Row Source Type: Table/Query
...
Default Value : 0

Combo Box Column Count culls data?

Basically, I have a combo box that I'm using to select a record. That combo box then populates several textbox's that are found on my form based on the ID. See the two images:
.
I'd like the combo box to show the first two columns in my query, which consists of 16 fields. The Abbreviation and the Name, to be exact. However, I found that if I hid the fields in the query or if I limited the column count of the combo box so it only displays the two, it actually culled the data so that the textbox's would not find it (thus be blank).
My question is, how can I just show the first two columns of the combo box yet still use it's ID to reference all sixteen?
Query
SELECT Tradeshows.tradeShowAppreviation,
Tradeshows.tradeShowName, Tradeshows.tradeShowID,
Tradeshows.tradeShowWebsite, Tradeshows.tradeShowLocation,
Tradeshows.tradeShowDateStart, Tradeshows.tradeShowDateEnd,
Tradeshows.tradeShowBoothSize, Tradeshows.tradeShowShipDate,
Tradeshows.tradeShowAudience, Tradeshows.tradeShowFocus,
Tradeshows.tradeShowMailer, Tradeshows.tradeShowDoorDrop,
Tradeshows.tradeShowProductFocus, Tradeshows.tradeShowAttendees,
Tradeshows.tradeShowMembers, Tradeshows.tradeShowMemberships
FROM Tradeshows;
Do not change the column count, change the column widths.
Column width: 0cm;2cm;1cm;0cm
And so on.
it should not be difficult to only select the relevant columns. You could post the Row Source property of your combo.
It seems to me that you should be binding you table to the data source TradeShows and using the wizard to create a combobox that finds record.
You can do this by selecting the table Tradeshows and choosing either create form or form. You will now have a form with the RecordSource property set to TradeShows. Next, choose to add a combobox to the form, ensuring that you have selected the wizard (the magic wand button is highlighted). You will be given the option to "Find a record on my form based on the value I select in my combobox". You can choose this and step through the wizard. When you get to the step where you choose fields, make sure you choose the TradeShowID first, and then the name and / or abbreviation. If TradeShowID is the primary key, as it should be, the column will be automatically hidden in the next step, which will show the fields selected.
The result of these actions will be a combobox with the following properties:
Row Source : SELECT [Tradeshows].[tradeShowID], [Tradeshows].[tradeShowName],
[Tradeshows].[tradeShowAppreviation] FROM [Tradeshows];
Bound Column : 1
Column Count : 3
Column Widths : 0cm;2.54cm;2.54cm
You will also have [Embedded Macro] in the After Update event (2010 and possible 2007) or [Event Procedure] for earlier versions. The wizard code is pretty poor, but that is another days work.
If you still wish to do all the work of setting each control to the (possibly changing) column order, you can follow a similar lay out for the combo, setting counts and widths appropriately.

Report Builder 3.0 - How to sum output of expression

We are looking to sum the output of an expression meaning that it does not exist as a field. Is there a way that that we can sum the content of a range of tablix cells?
In the above screen capture i am looking to have the total of <<"Expr">> displayed in the Total column.
No. You need to provide an expression that computes the total directly. You can only reference the contents of cells (using the ReportItems collection) that have scope "higher" than the current scope. In other words, you can reference a total text box in a non-total tablix cell, but you cannot reference a non-total tablix cell in a total text box.

How can I bind a multi-row update or insert statement to a form?

I have a table Prices:
ID -- primary key, autonumber long integer
PriceDate -- Date
Price - Currency
Quantity - Number, DECIMAL subtype
UnitPrice - Number, DECIMAL subtype (an update statement is run to keep this in synch with price and quantity, but it's just a convenience for indexing... probably it'll be replaced with an expression in my queries)
ItemNote - Text
NewStores_ID - long integer key, lookup to another table of stores
NewItems_ID - long integer key, lookup to another table of items
To enter prices for a given store on a given day, I would like to be able to select the store and date ONCE on a form, then enter the items individually in a datasheet. For reasons unexplained, this proves difficult.
I can create a subform binding everything but the store and price to a temp table TempPrices with the same structure as the original. Then I run the SQL statement
INSERT INTO Prices
(PriceDate,Price,Quantity,UnitPrice,Brand,ItemNote,NewStores_ID,NewItems_ID)
SELECT
PriceDate,Price,Quantity,Price/Quantity AS
UnitPrice,Brand,ItemNote,NewStores_ID,NewItems_ID)
FROM Temp_Prices;
This will feed all the new rows into the main table. But, when I want to set the store and date only once, I run into problems. I've tried using named parameters for date an store in the insert statement... which can cause a pop-up prompt, but I cannot bind it to a form control. I've tried binding an update statement for those fields in the temp table to a form... but it doesn't even show an option to bind a multi-row update.
How can I get this to work with a minimum of clumsy hackery? It seems like there ought to be a simple solution, and if I were using something like PHP or JDBC I'd just run an extra query.
Edit: changed storage type for Quantity and UnitPrice to Number, Decimal subtype in place of double float. Just so people won't cry about using a float in any proximity to currency. It doesn't pose a problem in my use, but there are enough people who have a knee-jerk reaction to that.
Edit 2: Form/Subform
I'm trying to structure this as a master form with a either fields for entering store name and date, or a subform for the same, then a subform mapping to the temporary table for entering pricing data. There is an action button to run the insert/update queries to dump the temp table into my main prices table and clear out the temp table. However, the problem is that I can't figure out how to get the date/store fields in the master (or subform) to bind to an insert/update value applied to all the new rows at once.
Edit 3: SQL Statements (for clarity)
INSERT INTO
PRICES(NewStores_ID,PriceDate,NewItems_ID,Brand,Price,Quantity,
UnitPrice,ItemNote)
SELECT
#MyStore_ID,#MyPriceDate,NewItems_ID,Brand,Price,Quantity,
Price/Quantity,ItemNote
FROM TempPrices;
UPDATE TempPrices SET PriceDate=#MyPriceDate,NewStores_ID=#MyStoreID;
For these queries, I cannot bind parameters for #MyStore_ID or #MyPriceDate to fields in any form. The queries don't show up as options when trying to link them to a form. I can run them and get popup boxes to input parameters, but that's not what I want.
This is the target I'm aiming at:
"I would like to be able to select the store and date ONCE on a form, then enter the items individually in a datasheet."
However, if you have a reason why you need to do it with a temp table and DML statements, then this suggestion will not be useful.
I created a Prices table with only 4 fields, then a query on that table which I used as the Record Source for a form, "fsubPrices":
SELECT p.ID, p.NewStores_ID, p.PriceDate, p.Price
FROM Prices AS p
ORDER BY p.NewStores_ID, p.PriceDate;
The form has text boxes (txtNewStores_ID, txtPriceDate, and txtPrice) bound to the similarly-named query fields. I set Enabled=Yes for txtPrice, and Enabled=No for the other two.
Then I created an unbound form "frmPrices", and in the form header added a combo box "cboStores" and a text box "txtPriceDate". The combo has Bound Column = 1 with this query for its Row Source:
SELECT l.Store_ID, l.Store_name FROM tblkupStores AS l ORDER BY l.Store_name;
Then I added fsubPrices as a subform control to the detail section of frmPrices. The tricky part is setting the Link Master/Child Fields. There is a "wizardy dialog thing", but it will only allow you to select from the available fields, and I needed to link controls on the main form with fields on the subform. To do that, I had to type what I wanted directly into the subform control's property sheet:
Link Child Fields......NewStores_ID;PriceDate
Link Master Fields.....cboStores;txtPriceDate
The result is ... choose a store and date combination in the main form ... any matching records are displayed in the subform. You can navigate to the "new record" in the subform to add records for that store/date combination. But the txtNewStores_ID and txtPriceDate controls don't show the updated values until the new record is saved.
I hope this is close to what you want. It's actually fairly quick and easy to create; not so easy to describe.
You can't really do that. You are always going to have one row being worked with at a time.
What you can do is simulate it by changing the form's Default View from "Single Form" to "Continuous Form" or perhaps "Data sheet" and making is a child(sub) form of a master form.
Then you can put the store and date on the Master form, and linking to the child form using the NewStores_ID and PriceDate fields.