First of all, your variable names are crap, you need to fix those
- don’t call it ‘Vendrs’, call it “Vendor”. It’s based on the “Vendor” table, so you need to call it “Vendor” like standard C/AL.
- don’t call it ‘Vend’, call it “VendorNo”
- don’t call it ‘Nam’, call it “Name”, or “VendorName”. Why on earth would you leave off just one letter?
- don’t call it ‘Ad’, call it “Address”, or “VendorAddress”
Unclear variable names make code difficult to read. Programming is hard enough as it is, make it easier on yourself and everyone else after you that has to do maintenance on your code by using variable names that make sense.
You really don’t need to put the field values into variables at all, because you can use Vendor.“No.” directly in SourceExpr.
You have to think about this. The “Vendor No” field stores the primary key value of the Vendor table, so you would never use filters on the Vendor’s “No.” field. You know the primary key value, so you need to GET the Vendor record to be able to access any of the Vendor’s field values. You should be able to do just Vendor.GET(“Enquiry Line”.“Vendor No.”); and then set the SourceExpr of the report controls directly to the Vendor’s field values. Maybe you can check the value in the Vendor No field and do something like this:
IF “Enquiry Line”.“Vendor No.” = ‘’ THEN BEGIN
END ELSE BEGIN
Vendor.GET(“Enquiry Line”.“Vendor No.”);
That way, if the Vendor number is blank, the field values should be blank as well.
Then finally, you need to think about which Enquiry Line you need to look at, and where the Vendor details go. You say it goes into the report’s header, yet you program the Enquiry Line dataitem to retrieve the information. The last one is marked ‘Print’, but it is showing the details for the first line. Think about that. Observe and follow along the thinking. Debug the report and walk through it step by step. Figure out why it is looking at the first one and not the one you need. Think about the control flow of a report object. What happens first, when are sections printed, when is data retrieved. Chances are that you will find that the report header is rendered well before it gets to the right Enquiry Line.
You probably have that code in the wrong place. Maybe the code that retrieves the Vendor information should go somewhere else. Maybe you need to program a new EnquiryLine variable, on which you set a filter on the ‘Print’ field, in order to retrieve the right record, and use the Vendor No on that one.