4 Replies Latest reply: Sep 10, 2012 8:59 AM by CraigB RSS

    Adding records int BLOCK depending on a loop

    940100
      Hi all,

      I am experiencing problems doing the following:

      When i push a button i call a cursor that returns several records, depending on some values on that record i should add or not a record to a block.

      Somoeone could tell me how to do it, i am doing:

      GO_BLOCK('BLOCK');
      FOR reg in cursor
      LOOP
      ..
      ..
      if reg.value = 'S' then
      create_record;
      :BLOCK.VALUE = 'S';
      end if;
      ..
      ..
      END LOOP
      close cursor;
      Exception
      when others
      close cursor;


      thx in advance!!!
        • 1. Re: Adding records int BLOCK depending on a loop
          CraigB
          I am experiencing problems doing the following:
          What are the problems you are experiencing? Is your datablock based on a table or is it a Control Block? While not critical, it would also be helpful to know which version of Forms you are using.

          Craig...
          • 2. Re: Adding records int BLOCK depending on a loop
            frm40735
            you don't really need a create_record statment, you just assign the values to the block and put a next_record statement in your loop
            you also might want to clean up and if the last record is blank, delete it or move focus to first_record.
            like the previous reply, sort of difficult assisting when we don't know all the particulars.

            good luck
            • 3. Re: Adding records int BLOCK depending on a loop
              940100
              Hi all,

              The problem i experience is the FRM-40102.

              I am using Forms10,

              thx all.
              • 4. Re: Adding records int BLOCK depending on a loop
                CraigB
                The problem i experience is the FRM-40102.
                The "FRM 40102 Records must be inserted or deleted first" error implies that you already have a "New" record/row in your form so when you call the CREATE_RECORD built-in Forms is telling you that you haven't met the minimum required values for the current "new" record so you can't create a new one.

                As Frm40735 suggests (nice choice of name, by the way), rather than use the Create_Record, I recommend you check to see if the row the cursor is on is a new record before attempting to create a new record. Your code would look something like this:
                GO_BLOCK('BLOCK');
                  FOR reg in cursor
                    LOOP
                    ..
                    ..
                    if reg.value = 'S' then
                      If (:system.record_status != 'NEW') THEN 
                        create_record;
                      END IF;
                    :BLOCK.VALUE = 'S';
                    end if;
                    ..
                    ..
                  END LOOP
                  close cursor;
                Exception
                  when others
                    close cursor;
                Hope this helps,
                Craig B-)

                If someone's response is helpful or correct, please mark it accordingly.