Record shown twice in report

bRahms
bRahms Member Posts: 44
Hi again,

we managed to put in our report different fields of several tables.

But when we are trying to link the DossierID with the PersoneelslidID, we're getting no error, but something strange:
The first record is shown twice, and then it works "correct", with a delay of 1 record (since the first one is shown twice). The code we are using to find is:
recBegeleiderPJ.RESET;
recBegeleiderPJ.SETCURRENTKEY(PersoneelslidID, DossierID);
recBegeleiderPJ.SETFILTER(DossierID, '=%1', DossierID);
recBegeleiderPJ.FIND('-');


  IF recBegeleiderPJ.PersoneelslidID <> 0 THEN BEGIN
  recbegeleider.RESET;
  recbegeleider.SETCURRENTKEY(PersoneelslidID);
  recbegeleider.SETRANGE(PersoneelslidID, recBegeleiderPJ.PersoneelslidID);
  recbegeleider.FIND('-');
  END ELSE BEGIN
  EXIT;
  END;

Comments

  • lubost
    lubost Member Posts: 633
    I prefer "normal" way to create report:
    1. Create dataitem recBegeleiderPJ with appropriata Tableview property setting
    2. Create dataitem recbegeleider with appropriate Tableview property setting and linked to recBegeleiderPJ dataitem by PersoneelslidID
    3. Fill fields in needec sections
  • bRahms
    bRahms Member Posts: 44
    thx for your help, but since we are beginners i have to admit i don't know what you mean exactly.. can you be a more specific?
  • kine
    kine Member Posts: 12,562
    Please, go through some manuals for "how to create basic reports". It is just about creating two nested dataitems in the report, and connecting them through properties. For example see standard report 3 G/L Register for two nested dataitems...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bRahms
    bRahms Member Posts: 44
    We know how to make basic reports, it's just strange that he does it all correctly (!!), except for the first record. :(
  • bRahms
    bRahms Member Posts: 44
    We only want to know what we're doing wrong in the code we've given. There has to be something in it that says "Use the same PersoneelslidID for the first to DossierID's.

    DossierID 1 -> PersoneelslidID 1
    DossierID 2 -> PersoneelslidID 1
    DossierID 3 -> PersoneelslidID 2

    While it has to be

    DossierID 1 -> PersoneelslidID 1
    DossierID 2 -> PersoneelslidID 2
    DossierID 3 -> PersoneelslidID 3
  • bRahms
    bRahms Member Posts: 44
    nobody?
  • lubost
    lubost Member Posts: 633
    If you really want to create report by your way, there are some errors in your code:
    recBegeleiderPJ.RESET;
    recBegeleiderPJ.SETCURRENTKEY(PersoneelslidID, DossierID); may take a long time to filter, because key is not optimal
    recBegeleiderPJ.SETFILTER(DossierID, '=%1', DossierID);
    //recBegeleiderPJ.FIND('-');
    if recBegeleiderPJ.FIND('-') then ...


    IF recBegeleiderPJ.PersoneelslidID <> 0 THEN BEGIN
    recbegeleider.RESET;
    recbegeleider.SETCURRENTKEY(PersoneelslidID);
    recbegeleider.SETRANGE(PersoneelslidID, recBegeleiderPJ.PersoneelslidID);
    // recbegeleider.FIND('-');
    if recbegeleider.FIND('-') then ...
    END ELSE BEGIN
    EXIT;
    END;

    but it is hard to find mistake exactly because I have to see the whole object.
  • kine
    kine Member Posts: 12,562
    bRahms wrote:
    We know how to make basic reports, it's just strange that he does it all correctly (!!), except for the first record. :(

    If it is not working, it is not done correctly... 8)

    Can you post whole code (including names of triggers where the code is used)?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bRahms
    bRahms Member Posts: 44
    Name	DataType	Subtype	Length
    recdossier	Record	tblDossier	
    recjongere	Record	tblJongere	
    recbegeleider	Record	tblPersoneelslid	
    recBegeleiderPJ	Record	tblDossierPerPersoneelslid
    

    We used tblDossier to buid up the report (the part of it that is used for what we want, we've got several Dataitems)

    Want we want is that when there is a particular DossierID chosen in a field below, that the PersoneelslidID is shown that is linked to that DossierID via tblDossierPerPersoonelslid.

    We tought we could manage that through the given code in the beginning. He does what we want it to do, he links the DossierID's to the PersooneelslidID, but then he shows the first record twice, so the rest doesn't match the right PersooneelslidID, but the PersooneelslidID-1.
  • kine
    kine Member Posts: 12,562
    Still I do not know in which trigger you are setting the records. You need to do it on correct trigger because the triggers are called in some order and the values are printed between them, and if you change the value after the section is printed, the values will be shifted.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bRahms
    bRahms Member Posts: 44
    tblDossier, Header (1) - OnPreSection()

    is it that you mean? 8-[
  • bRahms
    bRahms Member Posts: 44
    or not? :p
  • lubost
    lubost Member Posts: 633
    You have to have three dataitems:
    tblDossier
    tblDossierPerPersoneelslid - indented and linked to tblDossier by DossierID
    tblPersoneelslid - two times indented and linked to tblDossierPerPersoneelslid by PersoneelslidID

    Nothing to code, only insert fields to desired section.
  • Mbad
    Mbad Member Posts: 344
    Code on section, not using the dataitems, names all screwed up. No wonder your code doesnt work. On presection it has already found the first record. Take a programming course and read the programmers, and developers guides.
  • DenSter
    DenSter Member Posts: 8,307
    You should write ALL of your data code in the dataitem triggers, and NONE of it in any of the section triggers. The section triggers should only be used to determine whether to print the section, to set fonts, positions etcetera.