Options

Counting no. of records selected

ptijsmaptijsma Member Posts: 17
Hello,

I want to count the no. of records selected in a Tablebox. (Selected, not marked)

If No. selected eq 1 i need to get info out of this record (thats easy), and when No. > 1 do nothing. (thats the tricky part cause i cant find a way to count the number of records selected)

Any help is much appreciated.

Screenschot:
https://mail.rainbowsolutions.nl/CHE6004679.GIF


Thanks

Peter

Comments

  • Options
    Michael_SprungMichael_Sprung Member Posts: 6
    Change the properties of the textbox:

    Editable: No
    SourceExpression: COUNT

    Even if you set any filters, this field will be updated automatically.

    Is this the solution of your problem?

    Regards
    Michael

    :o
  • Options
    ptijsmaptijsma Member Posts: 17
    The problem is, that the user still must be allowed to change the value in the textbox.
    Also, the textbox may only be filled with the first record selected. So if more that one record selected, nothing may happen after the first selected.
  • Options
    SteveOSteveO Member Posts: 164
    Check out the SETSELECTIONFILTER command.

    Perhaps that might help in some way??
    This isn't a signature, I type this at the bottom of every message
  • Options
    ptijsmaptijsma Member Posts: 17
    Nope. Tried that but the problem is that SETSELECTIONFILTER sets a mark on all selected records AND sets the filter to MARKEDONLY.

    Because the event needs to be triggered at OnAfterGetCurrRecord, the subform, remains empty BEFORE anything can be selected (because the fitler is set to MARKEDONLY).

    Best thing would be to:
    1. SETSELECTIONFILTER
    2. Count records within the filter
    3. Programming logic to update the field
    4. Reset FILTER to what it was before point 1.

    I only don't know how to achieve this, every time i tried something like this, my subform remained ampty, before anything was selected.
  • Options
    fbfb Member Posts: 246
    I think that you are almost there. You just need to do the work in a copy of the current Rec.

    Create a local variable -- 'MyRec', type Record, subtype <same record as the form>.

    Then in the trigger, do something like this:
    MyRec.COPY(Rec);
    MyRec.SETSELECTIONFILTER;
    IF MyRec.COUNT = 1 THEN BEGIN
      // do your stuff here...
    END;
    
    Because the SETSELECTIONFILTER is applied to MyRec, the form's Rec is left undisturbed...
  • Options
    pdjpdj Member Posts: 643
    You should (almost) never use SETSELECTIONFILTER on rec, always it on a local variable.
    CurrForm.SETSELECTIONFILTER(MyRec); 
    IF MyRec.COUNT = 1 THEN BEGIN 
      // do your stuff here... 
    END;
    
    I.e. read this thread for details: http://mibuso.com/forum/viewtopic.php?t=3734&
    Regards
    Peter
Sign In or Register to comment.