Options

Filter on specific record with RecordRef or FieldRef

westerwester Member Posts: 33
Hi there.
I wish to filter my recordset to a specific record, but it seems to give me troubles. I've tried 2 different approaches, but each of them just ignores my way of setting a filter, and returns the value of the very first record in the table.

The following code is run within a REPEAT-LOOP, which changes the: "ChosenField" variable to a different field in the record after each LOOP.

*** SEE CODE IN NEXT POSTING BELOW THIS...

In example 1 I've used the SETPOSITION method, and in example 2 I've used the SETRANGE-method of the FieldRef function.
None of them filters the recordset.

Can anyone see what I'm doing wrong?

Thank you for reading this.

/Wester

Comments

  • Options
    westerwester Member Posts: 33
    The code looks like this:
    NaviTable := 18;
    CurrPrimaryKeyField := 'No.';
    WantedRec := '502200';

    // Example 1:
    RecRef.OPEN(NaviTable);
    RecRef.SETPOSITION('"' + CurrPrimaryKeyField + '"=FILTER(' + WantedRec + ')');
    FldRef := RecRef.FIELD(ChosenField);
    IF RecRef.FIND('-') THEN BEGIN
    MESSAGE(FORMAT(FldRef.VALUE));
    RecRef.CLOSE;
    END;

    // Example 2:
    RecRef.OPEN(NaviTable);
    FldRef := RecRef.FIELD(ChosenField);
    FldRef.SETRANGE(CurrPrimaryKeyField, WantedRec);
    IF RecRef.FIND('-') THEN BEGIN
    MESSAGE(FORMAT(FldRef.VALUE));
    RecRef.CLOSE;
    END;
  • Options
    fbfb Member Posts: 246
    Example 1: SETPOSITION does not set any filters, it simply places values in the primary key field(s) of the record. After SETPOSITION, use FIND('=') instead of FIND('-')...

    Example 2: The syntax of SETRANGE for FldRefs is SETRANGE(FromValue,ThruValue), where you can omit ThruValue for a single value filter. So, I think you meant to code it FldRef.SETRANGE(WantedRec);
Sign In or Register to comment.