How to populate a text item from Oracle table using Oracle forms (Middleware) 11gR2 - database

I am using Oracle with Oracle Forms builder (Middleware) both 11gR2. I am creating a system for purchasing records. I have the following 2 tables.
(a) product (master) : prodid(PK), prodname ...... etc.
(b) purchase (detail) : prodid(FK), quantity, ...... etc.
My plan: All the product details will be in the product table. purchase table will be used only to input purchase information. This table can't input any new product. If any new name, that info will have to be input into product table first. This way I can reduce duplicate names.
Now I am having difficulties relating to prodname (name of the product) column in the form.
I created forms using the purchase table only. This table does not have the prodname (because I put this field in product table) column. But during data entry, they need to see the product name !
So I created text item (tabular, database - no). Then I created LOV, attached to text item, input the prodid in prodid field in the form. LOV part is fine.
I run the form. click the text item, LOV appears, select a name, click OK. product name, product id, etc. appears in their fields as it should be. LOV is working fine. Now I can only input data but having difficulties updating. I mean if I input a name (LOV) in the text item, press execute query, shows records from the database but names in the text item disappear. Since the name is not here, it's not comfortable to update.
I think LOV is not the good idea here. May be I need to use PL/SQL in a trigger somewhere.
But I could not figure it out. I searched google but no luck. Is there anyone who can give me any idea or some example code/trigger please.

Since the product name is an non-database item, when execute query runs, the field is cleared and since no column is assigned to that field, it doesn't repopulate.
The usual way to populate this field is to have a function which returns the product name based on the id that is pressed and call the funtion in POST-QUERY trigger.

Basically it's a pretty simple task but I was having difficulties due to the lack of my experience. However, what I have done is -
create the text item (name : product_name) in the canvas
set properties for the product_name (database : No, .... etc as needed).
Create a block level POST-QUERY trigger and write the PL/SQL block to populate the field. For example, I wrote the following.
BEGIN
SELECT prodname INTO :purchase.product_name
FROM product WHERE product.prodid = :purchase.prodid ;
END ;
That's it and when perform execute_query in the form, it will bring the product name from another table. - Query problem is solved.
Now create an LOV using product table to bring the product name and product id.
Associate this LOV to the product_name text item. So whenever you need to input information about a purchase, just use the LOV to populate the product name field. And then input the subsequent fields as well.
This way both of my issues (query and data entry) are resolved.
I did this according to the suggestions given by Sathya and a video (6 minutes) from the youtube at https://www.youtube.com/watch?v=0nqldnGt8KA.
Thanks to Sathya and youtube.

Related

Problem with Showing Query Results on a Form

I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.

Bound combo box in form does not always update table

I'm struggling with a problem which I can't work out is due to a logical error, a design error or both. Or maybe it's something else entirely.
I have created a simple customer services database and form based user-interface for my company. When a user answers the phone they are supposed to log the call in the system if it is an issue relating to a product.
Sometimes a chain of stores which we have a special relationship with calls up on behalf of customers and we take their reference number and give them ours. This system actually works pretty well if I may say so myself (!), but I noticed after a while that when this store calls up and gives us their number, when they are logged into the system their branch number/name is not updated in the table record.
Here is a summarised outline of the relevant database tables. I renamed the store to SpecialStore:
Issues
IssueReference
ProductID
CustomerID
SpecialStoreBranch
Customers
...
Products
...
SpecialStore
SS_ID
City
Address
The idea is that even if it is either a customer or the store with their own IDs, the products are still stored in the same Products table, just with either the CustomerID or SS_ID filled in. Then when issues are logged, the store or customer is set and logged against a product.
In my main form I have a variety of boxes for a new issue to be filled in. There are combo boxes to select the CustomerID, ProductID etc, and of course the SpecialStoreBranch. These are all bound to the table, and the combo boxes all have row sources relating to their particular table. E.g. CustomerID combo box is a list of the IDs in the Customers table. (This is filtered to the required one elsewhere in the form.)
The Issues table SpecialStoreBranch field has the following query as its Row Source:
SELECT SpecialStore.[SS_ID], [SpecialStore].[City] FROM SpecialStore;
This is the same row source for the combo box on my main form.
The Column Count is 2, with the Bound Column as 0 and the column widths, if necessary, are 1cm;2.544cm.
My main form combo box SpecialStoreBranch has the other attributes:
Limit to List = yes
Allow Value List Edits = no
Inherit Value List = yes
Show Only Row Source Values = no
On the form the CustomerID and ProductID store correctly when the record is saved, and they are also from combo boxes. The form refreshes to update those fields when another part of the form (adding new customers and products) is changed. Could this be why the SpecialStoreBranch does not update? What am I missing? Is there a way to test this? I have been trying to run user tests to see if it ever works, but all I know is that it doesn't always set. If I have forgotten a piece of information let me know.
Edit:
Looking here: BoundColumn-Propery, I'm not sure if setting the bound column to 0 is doing what I think it's doing. But even then it should still use that id number to input into the table I would have thought and if they are all the same, what does it matter. When I tried setting it to 1, it took the text value in the table. Confusing!

MS Access form to update multiple tables without subforms

I am quite new to creating dbs in Access but I am not a fan of subforms, I can already tell that much, they are nice for one to many relationships (one customer, many orders) but when I just want to reduce redundancy and create a one to one relationship between tables and I only at all times would need one record from another table, subforms no longer feel so nice.
My example:
I have 2 tables, 1 for companies (ID, company name, country ID) and one for countries (country ID, name of the country). To eliminate repetition of country names I use country ID to link the 2 tables, and only add the ID of the country, not its name.
When I create a form for the "companies" table I want one field that says where that company is located instead of a subform (because I still havent figured out how to hide the box around it), so practically having one field that's connected to a different table.
And then through the one to one connection, when a record is selected the form would show in one field where the company is located. Is this possible?
Extra: I have 2 countries in my "country" table, the UK and Germany, but a new company I am adding a record from this form, is located in France, is it possible that I just enter France into the field and it automatically creates a new record in the "country" table for France, and also adds the new record's ID to the "company" table, to the company that's located in France
It seems your form and subform are based directly on tables. Try basing your main form on a query:
SELECT
company.ID,
company.CompanyName,
company.CountryID,
country.CountryName
FROM
company
INNER JOIN country ON
company.CountryID = country.CountryID
This will eliminate the need for a subform.
Extra: You may actually want to have the 'country creation' function on a separate form, or invoked from a button push on this main form.
Having Country IDs to force users to pick a standard country from a list is a very good idea. However if you also let them arbitrarily enter new ones in the same box you're trying to prevent them from mistyping in, that good work can come undone.
Yes this is absolutely possible. The way I do this is with unbound forms, so I control all of the SQL statements to tell the data what to do and where to go.
Since you have 3 fields being sent into a row in the "companies" table and 2 fields being sent into a row in the countries table with 1 of the fields being in a relationship (I'm assuming 1 to many), create 4 textboxes (or whatever other control) on your form. The controls will be for: ID (assuming this is inputted by the user and not an autonumber. If it is, please comment below), company name, country ID, name of country. When you fill all of them out, have a button with a Click event. In here you will have 2 SQL statements to insert records, 1 for each table.
The code will look like this:
Private Sub button_Click()
DoCmd.RunSQL "INSERT INTO companies VALUES ([ID].Value, [company name].Value, [country ID].Value)"
' The words in the [] are the names of your controls on the form
DoCmd.RunSQL "INSERT INTO country VALUES ([country ID].value, [country name].value)"
End Sub

MS Access default value from another table

I have two tables in a database. One is called salesreceipt and the other is salesreceiptlinedetail.
Each row in salesreceiptlinedetail has a field IDKEY that matches a field TxnID in a row in salesreceipt. There can be multiple rows in salesreceiptlinedetail that can match the same row in salesreceipt.
I have third party software that syncs my access database with Salesforce. The software only allows querying one table in the database at a time.
I need to automatically copy some of the fields from the salesreceipt table to new fields in the salesreceiptlinedetail table so I can sync the data correctly.
I'm very new to MS access. After trying many different things I landed on a solution that I think may work but I'm not sure how to do it. It looks like I can set the default value of a field. I'm thinking I need to do a DLookup to find the field I want to copy in the salesreceipt table and somehow use criteria to check the IDKEY matches the TxnID. I think I need to create a module with a function to do this but I'm not sure how and how to call it.
I may be way off on this. I could use some help or ideas. I've been researching for hours and could use a little push in the right direction. Thanks in advance.
Here's some things you can try, though I'm making some assumptions about the tables you've got and the result you're looking for.
So you've got a table called salesreceipt with an ID field TxnID and some other data (e.g. CustomerRef_FullName):
And then you've got a salesreceiptlinedetail table that has a field IDKEY field that matches back to salesreceipt table's TxnID field (i.e. a foreign key) and an empty field (e.g. FullName) that you want data for by matching the record back to the salesreceipt table.
I can think of a few ways of achieving this so that you end up with a table that has the information you want, but I'm not sure which is best for you. All these options shown are using Access 2013.
1) Get the data using a SELECT query and export those results across to your third-party software:
In Access, go to Create / Query Design:
Add your salesreceipt and salesreceiptlinedetail tables to your query and then close the Show Table window:
Click and drag on the TxnID field to the IDKEY field to create a join (represented by a line in Access):
Double-click on the IDKEY from your salesreceiptlinedetail and CustomerRef_FullName from your salesreceipt table; they should show as fields in the area at the bottom (if you have other fields you need then add those too, I'm just going on 1 field for illustrative purposes):
Click run to see the result of this query:
Hopefully this is showing a table that's starting to fill-in the blanks you want:
You can then save the query (right-click on the query table and chose "save" and name it whatever you want):
And export the results to a spreadsheet (assuming spreadsheet is the format your third-party software takes). Go to External Data / and then click "Excel" from the export group:
The query with the name you saved it as will be there in the Access Objects side-bar so that you can run it and export the results again (double-click on it to run it again):
The good thing about this method is that it's faster than using DLOOKUPs (these can be resource-heavy if you have a lot of records) and if there is new data/records in your salesreceipt and salesreceiptlinedetail tables, the query will run on that new data and include it in its results without you having to modify the query.
For your question though, it sounded like you might want to populate your salesreceiptlinedetail table with the data you need... this SELECT query will not do that. If you want to populate the actual salesreceiptlinedetail table you will need an UPDATE query...
2) Populate empty fields in salesreceiptlinedetail using an UPDATE query matched to records from salesreceipt
In this example, we're going to populate an empty field in salesreceiptlinedetail, namely the FullName field. We're going to do this by matching records in salesreceiptlinedetail to salesreceipt using the IDKEY and TxnID fields and then bring across the corresponding data in the CustomerRef_FullName field to the FullName field.
To do this, setup a new query the same way we did in (1) above and stop after you complete this stage:
Change the Query Type to an "Update" query:
Double-click the empty field you want to populate, e.g. FullName from the salesreceiptlinedetail table:
In the "Update To" box, type the name of the corresponding table and field you want to use to populate your empty field. Enclose the table and field each by a pair of square brackets and separate each by dot. So it should look something like this:
[salesreceipt].[CustomerRef_FullName]
In the criteria box, match your IDKEY and TxnID fields, like this:
[salesreceiptlinedetail].[IDKEY]=[salesreceipt].[TxnID]
Click "Run" and Access should show a warning that it is about to update some records in a table. Click Yes to allow it to do this:
If you go back to your salesreceiptlinedetail table, you should see that the once empty FullName field is now populated:
You can then save your UPDATE query for use again later - be aware that double-clicking on the query will open it AND run the UPDATE again (i.e. it will attempt to populate your salesreceiptlinedetail table with new data), so if you don't want that to happen you can right-click on it and open it Design View before opting to run it.
This method is good if you want to populate data in an already existing table, rather than essentially building a new table of results out of existing tables as described in (1) when we used a SELECT query.
If there's new data in salesreceiptlinedetail or salesreceipt, you'll want to run this UPDATE query again.
This is to add to Matt's answer. We have similar situations for a miniature reporting database, where we need to update the database several times through out the day. We wrap the query in a function and schedule a task in Windows to run every 4 hours that executes the Access function and updates the data.

Change the displayed value in adf table

I am new working with ADF and Business component
I have a table with a columm with the department ID. This table is filled from another JSF page
I want to show the department name instead of the department Id
I have Business component with the view from my department table.
But I dont know how to show the department name instead de id in the adf table
My adf table is read only
you can create an LOV.Here you can select the type of attribute you need to display for the user externally(DNAME in your case) and type of value you need to store internally(DNO in your case) depending on the selected display value by the user.
Refer this link for LOV creation
http://techblogoracle.wordpress.com/2013/10/14/how-to-create-list-of-values-lov-in-oracle-adf/
Create a LOV in your VO for that property! Then you have two possibilities: 1- Reinsert your table in your page 2- Insert (re-insert) only the attribute that you need as a read-only column in that table!
To display the name of a department instead of the departmentId, create an LOV on the departmentId attribute in the view object that the ADF table is based on, pointing to the department view object.
To update your existing read-only table, remove the departmentId attribute from the JSF, and re-add it. Make sure that the new attribute is an "ADF select one choice." After the column has been added, select the select one choice drop down, and change the read-only attribute to true.
<af:selectOneChoice value="#{row.bindings.DepartmentId.inputValue}"
label="#{row.bindings.DepartmentId.label}"
required="#{bindings.Employees_VO1.hints.DepartmentId.mandatory}"
shortDesc="#{bindings.Employees_VO1.hints.DepartmentId.tooltip}"
id="soc1" readOnly="true">
If you run this page now, it should display the name of the department, instead of the id, while still being read-only.
How to show departmentName instead of departmentId using an LOV - ADF
If you're in the same taskflow or you share Data Controls and you don't want to change your VO to be based on two EOs, you can add a Transient attribute with the name, you will populate the value in the page that fills the data. Using LOVs it's too much of a headache. If the LOV list is big you will have performance issues that you introduce trying to solve a problem in a wrong way.
You can add referenced attributes to your VO.
So create a VO that is based on Emp and Dept together.
For example see the video here: https://blogs.oracle.com/shay/entry/whenvalidateitem_trigger_in_ad
use lov or use groovy Expression if number of values is not more than 2 or 3 values
usage : #{row.code eq 'A' ? 'Approved' : 'Rejected' }

Resources