Select order header record

imurphyimurphy Member Posts: 308
What am I doing wrong? The following code comes from a button I have placed on the Sales Orders form:
OrderHeader.RESET;
OrderHeader.SETRANGE("Document Type","Document Type");
OrderHeader.SETRANGE("No.","No.");

IF (OrderHeader.COUNT = 0) THEN
MESSAGE ('No header record found');

It should 'load' the Sales Order Header for the currently visible record on the form into OrderHeader ... no?

The same code works fine for selecting sales order lines.

What am I doing wrong?

-- Ian

Comments

  • krikikriki Member, Moderator Posts: 9,110
    The OrderHeader.COUNT just COUNTS the number of records. It does NOT get a record in the buffer.
    To get the record, you better do this:
    IF NOT OrderHeader.GET("Document Type",No.") THEN
    MESSAGE ('No header record found');

    Or if you also need the filters:

    OrderHeader.RESET;
    OrderHeader.SETRANGE("Document Type","Document Type");
    OrderHeader.SETRANGE("No.","No.");
    IF NOT OrderHeader.FINDFIRST THEN // or FIND('-') in pre 4.0SP1 versions
    MESSAGE ('No header record found');
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • imurphyimurphy Member Posts: 308
    I'd guess that SETFILTER or .NEXT have a sideeffect which does the same. This is some code which is working for Sales Lines:
    SalesLine.RESET;
    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    SalesLine.SETFILTER(Quantity,'<>0');
    
    IF (SalesLine.NEXT <> 0) THEN
    REPEAT
    .....
    UNTIL (SalesLine.NEXT = 0);
    

    Thanks for the pointer.

    Ian
  • krikikriki Member, Moderator Posts: 9,110
    To do some looping, you should use this:
    SalesLine.RESET;
    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    SalesLine.SETFILTER(Quantity,'<>0');
    
    IF SalesLine.FINDSET THEN // or FIND('-') but not FINDFIRST
    REPEAT
    .....
    UNTIL (SalesLine.NEXT = 0);
    
    If you use a NEXT to find the first record, you can't be sure of the result.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • bbrownbbrown Member Posts: 3,268
    imurphy wrote:
    What am I doing wrong? The following code comes from a button I have placed on the Sales Orders form:
    OrderHeader.RESET;
    OrderHeader.SETRANGE("Document Type","Document Type");
    OrderHeader.SETRANGE("No.","No.");

    IF (OrderHeader.COUNT = 0) THEN
    MESSAGE ('No header record found');

    It should 'load' the Sales Order Header for the currently visible record on the form into OrderHeader ... no?

    The same code works fine for selecting sales order lines.

    What am I doing wrong?

    -- Ian

    Since you already have the record, why retrieve it again?

    OrderHeader := Rec;
    There are no bugs - only undocumented features.
  • imurphyimurphy Member Posts: 308
    Now thats a well hidden little piece of info. Haven't noticed it being used in any of the internal forms I've been browsing through, they all seem to do something similar to what I've been doing.

    Thanks for that - should save me a load of time.

    Ian
  • awarnawarn Member Posts: 261
    Hey - just an FYI - you do not have to tell the form to go get anything from the database, it does that already, that is why you don't see normal forms putting any code in them to retreive database records.

    If you create a blank form based on the customer table, with just the no field on it, and scroll through the records, you'll see them flash through without the addition of any code.

    -a
  • imurphyimurphy Member Posts: 308
    By well hidden, I meant that searching the docs I can't find a single reference to the fact that rec is always assigned to the primary record on a card.

    CurrForm is the current form, so logically CurrRec or CurrRecord would be the current record and not rec.

    Searching for either of these shows up nothing and trawling through the code in various forms also doesn't show up much - though I'm sure it is used in some places.

    Ian
  • awarnawarn Member Posts: 261
    Well on a report there is CurrReport. but that refers to the report, not the record.

    You do not see it much because the scope of Rec means that you rarely need to actually type 'Rec'.

    On a sales order form, you do not need to type:

    Rec."No."

    just

    "No."

    Same thing in the sales order table, you can omit the Rec prefix.

    The place you do see Rec is when you press F5 and get the variable window up, then you can browse Rec for fields, functions, etc...

    -a
Sign In or Register to comment.