Show temporary table in subform

TbiTbi Member Posts: 33
Hi,

Is it possible to show records in a temporary table in a subform? I know it is possible to open a new form by using FORM.RUNMODAL 50000,rRecord), But what if I want to update a subform instead of opening a new?

Comments

  • fbfb Member Posts: 246
    In your subform, define a global variable 'TempRec' record of the same table as Rec -- be sure to set the 'Temporary' property.

    Define a function on the sub-form that will insert records into TempRec. The main form should call this function at the appropriate moments, when different records should show in the sub-form (possibly the OnAfterGetCurrentRecord trigger of the main form?).

    Then, place the following code in the appropriate sub-form triggers:
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    BEGIN
      TempRec := Rec;
      IF NOT TempRec.FIND(Which) THEN
        EXIT(FALSE);
      Rec := TempRec;
      EXIT(TRUE);
    END;
    
    Form - OnNextRecord(Steps : Integer) : Integer
    BEGIN
      TempRec := Rec;
      CurrentSteps := TempRec.NEXT(Steps);
      IF CurrentSteps <> 0 THEN
        Rec := TempRec;
      EXIT(CurrentSteps);
    END;
    
    Warning: This example does not extend to 'Editable' sub-forms. More work is necessary in other form triggers to insure that insert/modify/delete operations occur on 'TempRec' rather than 'Rec'.
  • pedroccdapedroccda Member Posts: 90
    But where is the property Temporary of the variable ?? I can't find it!!
    Kiki
  • fbfb Member Posts: 246
    In form design mode, choose 'View, C/AL Globals' and highlight the variable. Then choose 'View, Properties' (Shift-F4).
  • rwabelrwabel Member Posts: 32
    I've tried the same.
    I made a form based on the table country.
    Then I've declared a TempRec variable as record on the table country.
    Then I set the temporary propriety to make it a temp table.

    In the C/AL of my new form I've put your code in the 2 functions.
    I then needed to create a new variable CurrentSteps and definied it as integer.

    Put I only get a gray subform. Did I miss something or where could the problem be, that I don't get the data from the temp table in my subform?

    I hope someone can help me

    thanks
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    A Temprec variable doesn't contain records at first. You need some code to copy the data from the rec-variable to the temprec-variable, eg:
    IF FIND('-') THEN
      REPEAT
        tmprec := Rec;
        tmprec.INSERT;
      UNTIL NEXT = 0;
    
    You can write this code in the OnOpenForm-trigger.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • rwabelrwabel Member Posts: 32
    Thanks for the code, still doesn't work.
    I've now this code on my main form (not subform)
    Form - OnOpenForm()
    IF FIND('-') THEN
      REPEAT
        TempRec := Rec;
        TempRec.INSERT;
      UNTIL NEXT = 0;
    
    Form - OnCloseForm()
    
    Form - OnQueryCloseForm() : Boolean
    
    Form - OnActivateForm()
    
    Form - OnDeactivateForm()
    
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    TempRec := Rec;
    IF NOT TempRec.FIND(Which) THEN
      EXIT(FALSE);
    Rec := TempRec;
    EXIT(TRUE);
    
    Form - OnNextRecord(Steps : Integer) : Integer
    TempRec := Rec;
    
    CurrentSteps := TempRec.NEXT(Steps);
    IF CurrentSteps <> 0 THEN
    
      Rec := TempRec;
    EXIT(CurrentSteps);
    

    the subform is empty
    <Control1000000000> - OnActivate()
    
    <Control1000000000> - OnDeactivate()
    

    I've these 2 variables (global)
    Name	DataType	Subtype	Length
    TempRec	Record	Country	
    CurrentSteps	Integer
    
    TempRec has the property temporary yes

    Form property has as source table the table country

    I'm sure I'missing something or didn't understand correctly[/code]
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    All the code needs to be done on the form where you want the records to be displayed (so all the codes needs to be on the subform). It looks like if you are using a mainform/subform.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • rwabelrwabel Member Posts: 32
    I'm using a form with a subform. I want to have it on the subform, but I don't have the 2 functions in the subform. do I've to create them in the subform?
    It could also be a table box, I just need to get displayed a temporary table in a subform or a tablebox in a form.

    I've read several posts. but I've never achieved doing it
  • rwabelrwabel Member Posts: 32
    I've achieved to make a form with a subform. I've made some little mistakes :-)
    But it does write any changes I'm doing on the temp table directly in the original table.
  • ara3nara3n Member Posts: 9,257
    Here is a code you can use to display temporary records. Without messing with the form.


    TempSalesLine."Document no." := 'test' ;
    TempSalesLine."Document type" := TempSalesLine."Document type"::Order;
    TempSalesLine."Line No." := 1000;
    TempSalesLine.insert;
    FORM.RUNMODAL(0,TempSalesLine) ;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • emanuelemanuel Member Posts: 22
    fb wrote:
    In your subform, define a global variable 'TempRec' record of the same table as Rec -- be sure to set the 'Temporary' property.

    Define a function on the sub-form that will insert records into TempRec. The main form should call this function at the appropriate moments, when different records should show in the sub-form (possibly the OnAfterGetCurrentRecord trigger of the main form?).

    Then, place the following code in the appropriate sub-form triggers:
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    BEGIN
      TempRec := Rec;
      IF NOT TempRec.FIND(Which) THEN
        EXIT(FALSE);
      Rec := TempRec;
      EXIT(TRUE);
    END;
    
    Form - OnNextRecord(Steps : Integer) : Integer
    BEGIN
      TempRec := Rec;
      CurrentSteps := TempRec.NEXT(Steps);
      IF CurrentSteps <> 0 THEN
        Rec := TempRec;
      EXIT(CurrentSteps);
    END;
    
    Warning: This example does not extend to 'Editable' sub-forms. More work is necessary in other form triggers to insure that insert/modify/delete operations occur on 'TempRec' rather than 'Rec'.

    Thanks, it works great after placing CurrForm.UPDATE to the function that fills the temporary record.
    <--Emanuel-->
  • emanuelemanuel Member Posts: 22
    fb wrote:
    In your subform, define a global variable 'TempRec' record of the same table as Rec -- be sure to set the 'Temporary' property.

    Define a function on the sub-form that will insert records into TempRec. The main form should call this function at the appropriate moments, when different records should show in the sub-form (possibly the OnAfterGetCurrentRecord trigger of the main form?).

    Then, place the following code in the appropriate sub-form triggers:
    Form - OnFindRecord(Which : Text[1024]) : Boolean
    BEGIN
      TempRec := Rec;
      IF NOT TempRec.FIND(Which) THEN
        EXIT(FALSE);
      Rec := TempRec;
      EXIT(TRUE);
    END;
    
    Form - OnNextRecord(Steps : Integer) : Integer
    BEGIN
      TempRec := Rec;
      CurrentSteps := TempRec.NEXT(Steps);
      IF CurrentSteps <> 0 THEN
        Rec := TempRec;
      EXIT(CurrentSteps);
    END;
    
    Warning: This example does not extend to 'Editable' sub-forms. More work is necessary in other form triggers to insure that insert/modify/delete operations occur on 'TempRec' rather than 'Rec'.

    Thanks, it works great after placing CurrForm.UPDATE to the function that fills the temporary record.
    <--Emanuel-->
Sign In or Register to comment.