Two filtered subforms on one mainform

msingmsing Member Posts: 8
I have added a tab control to the bottom of the contact in our NAV 2009 database. I am trying to display 2 different filtered views of the contact comments. I have added a category field of type option that will be used to classify the comments. I want to have two subforms that only display the comments for one category.

I am able to make the comments display properly but when I try to insert a record into one of the subforms, if there is already a record for the other category i get an error saying that the line already exists. It appears that th eform is not populating the Sub No. field which is part of the primary key of the table. I have autosplitkey and populateAllFields enabled on the subforms.

Does anyone have any suggestions for how to make the system populate the key fields properly so I am able to insert records into each of the subforms?

Answers

  • matttraxmatttrax Member Posts: 2,309
    So you've set the view of the subform via the properties (like contact number or something), but then they select an option on the contact card, and that applies a filter to the subform?

    If I remember correctly, only the fields in the TableView property are automatically filled in. It's also hard to say exactly not knowing the structure of the table on your subform.
  • kinekine Member Posts: 12,562
    Is the type filtered only on one value and only once? If you will filter it in FILTERGROUP a and in FILTERGROUP b to same values, it is like when you have filter for two values and thus the PopulateAllFields will not work. It means filter the value only in the SourceView of the subpage NOR on the Subpage filter etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • msingmsing Member Posts: 8
    I am not sure if I explained the situation as well as I would have liked. I have added a tab control to the bottom of the contact card. Two of the tabs contain a subform control that is pointed to tabular form for the contact comments. What I am trying to accomplish is to have one tab display only comments of category A and another tab that display sonly the comments of category B. However, right now when I try to insert a comment in the subform for category A and then try to inset a record into the subform for category B, I get the error stating that it is a duplicate record.

    I have tried having both subform controls point to the same subform object and use a different filter in the link. I have also tried having separate form objects for each subform.

    The fields contained displayed in the subform are date, category(my additional field), comment, and last date. I also added all of the fields for the primary key (table name, No., sub No., Line No.) to the form and made their columns invisible on the form as well as setting the populateAllFields property to Yes as was suggested in another post on Mibuso. For some reason when I insert a record the Line No. field isn't incrementing properly between the two subforms so that they try and insert duplicate keys.
  • kinekine Member Posts: 12,562
    Ah, yes, of course, the type must be part of the primary key or you cannot use AutoSplitKey... the AutoSplitKey is calculating the new value based on records which are visible in the form, thus not seeing the line with the line no. but different type. You have two options:

    1) Add the type into the PK before the Line No. field (Line No. must be last)
    2) Not use the AutoSplitKey and fill the line no. by own code or use different approach.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • msingmsing Member Posts: 8
    That worked! I had tried adding the category field to the end of the key earlier but was getting an error pertaining to it not being the correct data type. I didn't realize that I would have to put it ahead of line No. for it to work properly. Thanks for your help.
  • kinekine Member Posts: 12,562
    You are welcome! The main precondition for AutoSplitKey is that the PK must end with Integer field which than will be used as the Line No. 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.