Lookup Issue

souravbsouravb Member Posts: 135
Hi,
I have a code which is creating a problem:





IF Type=0 THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher Type","Voucher Type");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher No.","Voucher No.");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
IF GVVoucherHdr."Account Type"=5 THEN
BEGIN
IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN
BEGIN
"No.":=GLAcc."No.";
Description:=GLAcc.Name;
END;
END;
END;
END;
END;

If the user selects Type 0(line level) and Account Type 5(in Header level)
then the G/L Account list form will open. Type 0 is G/L Account. I wrote the code in the OnLookup of No. field. The code is not working. Can anybody help

Comments

  • SLF25SLF25 Member Posts: 37
    Use debugger, indent your code, there is no need to find the record twice.
  • DenSterDenSter Member Posts: 8,305
    souravb wrote:
    IF Type=0 THEN
       BEGIN
         GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher Type","Voucher Type");
           IF GVVoucherHdr.FIND('-') THEN
              BEGIN
                GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher No.","Voucher No.");
                IF GVVoucherHdr.FIND('-') THEN
                   BEGIN
                     IF GVVoucherHdr."Account Type"=5 THEN
                        BEGIN
                          IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN
                             BEGIN
                                "No.":=GLAcc."No.";
                                Description:=GLAcc.Name;
                             END;
                        END;
                   END;
              END;
       END;
    
    Alrighty.... a number of problems here:
    1:
    don't do IF Type=0... that's not very nice to read. What is much nicer to read is to specify the type explicitly
    IF Type = Type::"G/L Account"
    

    2:
    Why are you nesting all of these IF statements? It looks like you're trying to find a record, so why not just set filters? There is no point in finding records more than once. Just set all the filters and THEN try to retrieve the values. By the way, if you're setting filters on a record variable, you don't have to specify the record variable again in the filter declaration. I'm not even trying to figure out what your code means, but clean it up to look something like this:
    GVVoucherHdr.SETRANGE("Voucher Type","Voucher Type"); 
    GVVoucherHdr.SETRANGE("Voucher No.","Voucher No."); 
    GVVoucherHdr.SETRANGE("Account Type","Account Type"::"Value 5");
    IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN 
      "No.":=GLAcc."No."; 
      Description:=GLAcc.Name; 
    END;
    

    3:
    What you really want to do though, is set a conditional table relation on the "No." field. Check out the Sales Line table for an example. You can specify a relationship to a different table based on the value of another field. You don't need all that code!!
Sign In or Register to comment.