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
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');
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Thanks for the pointer.
Ian
If you use a NEXT to find the first record, you can't be sure of the result.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Since you already have the record, why retrieve it again?
OrderHeader := Rec;
Thanks for that - should save me a load of time.
Ian
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
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
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