Temporary Recordset Confusion

headley27headley27 Member Posts: 188
I need to parse a single field from an existing table down to distinct values and then pass those values into a form (list).

I have an issue passing the values to the form.

I have setup a temporary record variable 'RecDistinct' and am successfully parsing the list down which, I have confirmed.

On my form there is a single field linked to recDistinct.Tier1.

What is displayed on the form is only the last distinct value, repeated a number of times (equivalent to the amount of records in the non-distinct table) and I am unsure how to correct this.

I must be missing something simple.
Form - OnOpenForm()

CLEAR(recDistinct);

IF Rec.FIND('-') THEN REPEAT
  IF (recDistinct.Tier1 <> Rec.Tier1) THEN BEGIN
      recDistinct.INIT;
      recDistinct := Rec;
      recDistinct.INSERT;
  END;
  recDistinct := Rec;
UNTIL Rec.NEXT=0;

IF recDistinct.FIND('-') THEN REPEAT
   MESSAGE(recDistinct.Tier1);
UNTIL recDistinct.NEXT=0;

Many thanks in advance.

Comments

  • krikikriki Member, Moderator Posts: 9,118
    IMPORTANT : "recDistinct" MUST be a temptable!!!!!

    Form - OnOpenForm()
    // Clean old values in the temptable
    recDistinct.RESET;
    recDistinct.DELETEALL(FALSE);
    
    IF Rec.FIND('-') THEN 
      REPEAT
        recDistinct.RESET;
        recDistinct.SETRANGE(Tier1,Rec.Tier1);
        IF NOT recDistinct.FINDFIRST THEN BEGIN
          recDistinct := Rec;
          recDistinct.INSERT;
        END;
    UNTIL Rec.NEXT=0;
    
    IF recDistinct.FIND('-') THEN REPEAT
       MESSAGE('%1',recDistinct.Tier1);
    UNTIL recDistinct.NEXT=0;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • headley27headley27 Member Posts: 188
    Thanks kriki,

    I am using 3.7 so I can't use the FINDFIRST function.

    I guess that I should mention that I am confused because my Temporary Table 'RecDistinct' does contain the correct distinct values (which I have confirmed by the Message function), but I am not sure that I am 'linking' the form field properly to the Temporary Table.

    Am I correct by 'linking' the field to recDistinct.Tier1 via the SourceExpr property or should I be doing something else?
  • krikikriki Member, Moderator Posts: 9,118
    Instead of FINDFIRST, you can use FIND('-')

    You need "SourceExpr" to link it. But you temptable didn't contain the correct records.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • headley27headley27 Member Posts: 188
    IF recDistinct.FIND('-') THEN REPEAT 
       MESSAGE(recDistinct.Tier1); 
    UNTIL recDistinct.NEXT=0;
    
    is returning the expected values.

    I can't figure out why my form is not grabbing the values that the message box gives me.

    Something is missing here but I just don't see it.

    Thanks for your assistance kriki.
  • krikikriki Member, Moderator Posts: 9,118
    headley27 wrote:
    IF recDistinct.FIND('-') THEN REPEAT 
       MESSAGE(recDistinct.Tier1); 
    UNTIL recDistinct.NEXT=0;
    
    is returning the expected values.

    I can't figure out why my form is not grabbing the values that the message box gives me.

    Something is missing here but I just don't see it.

    Thanks for your assistance kriki.
    Use the form-wizard to make a new form from scratch based on the real table.
    Use this new form to show the records of the temptable and see if they are correct. If they are correct, it means your old form has some error in it. If the are wrong, it means that the values you expected are wrong.
    To call a form based on a temptable:
    FORM.RUNMODAL(FORM::"The Form",recDistinct);
    
    And "recDistinct" is your temptable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.