I'm trying to use this code to save data in a table by pressing a button in a non database data block (for auditing purpose):
if :system.cursor_value is not null then
insert into tab(col1,col2) values (:system.cursor_item, :system.cursor_value);
exit when :system.cursor_value is null;
but this code doesn't save any data in tab table! Why? and how to solve this problem?
Note: I'm using Oracle DB 10g, Forms 6i
It is not working because :system.cursor_value will be null, . The focus of the :system.cursor_item will be on the button, which has no cursor_value value. A simple way to test it would be to add the following debug to your code when you press the button i.e. the when-button-pressed trigger.
message(:system.cursor_item ||' :: '||:system.cursor_value,acknowledge);
1. If you have to have a the data block as a control/NBT block then Issue a go_item() or a go_block() to the block containing the data.
2. Why not just change block with the data into a real data block and change the code on the button to just perform a COMMIT_FORM; Create a when-validate-item at block level that will validate each item getting the item name (alternatively you could place the trigger against each item that is validating).
Instead of :system variables I would use the exact block and item name's. From your post is not clear why you don't do that but use cursor_value instead.
You can try to set button's property "Mouse navigable" to "no". The item with data will not lose focus and system.cursor_value may work. Also consider setting "Keyboard navigable" property to "No" because user can press this button using keyboard.
Some clearance on what and why you are trying to do may issue a more useful answer
You are right Q_Stephenson,
I've used your hints specially :system.cursor_value like this: if :system.cursor_value = 'someblock.someitem' -- the last text item in someblock block, and go_block also. Thank you
I've used :system variables because I want to save every value enterd in any text item in a table in the database (for auditing purpose), I don't want to use that routine way which return block_name.item_name suppose the block contains 50 text items in this case I have to write 50 statements!. Thank you for your help