Prevent subform from loading

ECEC Member Posts: 56
Sorry for spamming the forum :-)

Does anyone know how to prevent a subform from loading?

I have a subform which i want to be shown if the user selects a special option, otherwise the subform should not be shown. If the subform is loaded when the user has selected anything but the special option, an error occurs as the subform tries to filter/find some records (acording to the selection) that does not exist.

Any way to prevent this?

I hope you understand what i mean.

/EC

Comments

  • easabanganeasabangan Member Posts: 114
    1. Name your subform.

    2. On the OnInit trigger of your form put this code.
    CurrForm.YourSubformName.VISIBLE := FALSE;

    3. On the Validate Trigger of your Option Button put this code
    CurrForm.YourSubformName.VISIBLE := TRUE;

    Hope this helps
    No future at CPI
  • ECEC Member Posts: 56
    I can't. The following error occurs "The form can't recognize the controlelement XXXXXXX".

    Even if it could I don't think this would solve my problem. As setting hte subform to
    VISIBLE := FALSE;
    
    will not prevent the subform fron loading, and when it loads it sets the range according to what the user selected. If the user selects anything but the special option, the subform will fail and then close.
  • kinekine Member Posts: 12,562
    The problem is somewhere else - why the subform is creating error? You can solve this problem... :-)

    You need to enable the DelayedInsert property on the subform...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ECEC Member Posts: 56
    The error occurs because I've set SubFormLink om my subform. Is there any other to setting this programmatically?
  • Torben_R.Torben_R. Member Posts: 99
    I normally use a combination of ENABLED and VISIBLE
    IF Status = Status::Active THEN
      CurrForm.Subform.ENABLED := TRUE
    ELSE
      CurrForm.Subform.ENABLED := FALSEE;
    CurrForm.Subform.VISIBLE := CurrForm.Subform.ENABLED;
    

    and it works perfect for me.
  • ECEC Member Posts: 56
    Torben,
    Although it is a good solution, it doesn't solve my problem. The subform somehow still loads (although neither Enabled or Visible). An error still occurs as the subform tries to sort by an invalid value.

    E.g. My subform's SubFormLink is set to Status = FIELD(Status).
    In the table that the subform represents there are only values where Status is = Active.

    If the user chooses status = Inactive the subform fails with an error saying something like "Status 'Inactive' doesn't exist'.

    Does this clarify my problem a bit?

    /EC
  • kinekine Member Posts: 12,562
    It seems like you have not synchronous options on the fields you are linking or there is not correct code setting the filters. Try to enable debugger, run the form, simulate the problem and look where the debugger will stop. After that, try to send us the code where is the problem (if it is in code). Else you are linking fields with different options...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ECEC Member Posts: 56
    Kine,
    I have tried debugging and it doesn't seem the problem is in code but in the SubFormLink. The problem is that the subformlink only applies to when a specific value is set, f.ex. Active. If value is set to Inactive the subformlink does not apply and will yield no result.

    That's why I want to prevent the subform from loading.


    /EC
  • kinekine Member Posts: 12,562
    Can you post OptionStringML for the <your header>.STATUS field and <your lines>.STATUS field?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ECEC Member Posts: 56
    Well, the thing is that I only want to show the subform if the status equals Active. Otherwise I don't wanna load the subform as this generates the error I'm getting.

    So my header has several OptionStrings. Lets call them Opt1, Opt2, Opt3.
    The subform in question has subformlink set to Status = Field(Opt1).

    If the user user Opt2, the subform loads and the before-mentioned error occurs. Because Status = Opt2 does not exist in the table represented by the subform.
  • kinekine Member Posts: 12,562
    Ok, than, it is better to filter the subform through TableView (SubFormView) with fixed filter and do not use this in SubformLink...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ECEC Member Posts: 56
    Actually, I just discovered that the table filters on a order Number.
    This order number exists if status is set to Active, but not when set to Inactive.
    Then the subform fails as the order number does not exist. Sorry for the confusion.
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    There must be some other problem - if a filter has an empty record set, that should not throw an error - if it did that, you could never look at an invoice form with zero lines.
  • jesamjesam Member Posts: 100
    EC, did you find the solution to your problem ? I'm having the exact same problem and I don't understand why.
    I can't see the difference between what I try to do and a SalesHeader/SalesLine master detail form, yet there must be something different.
  • p1cp1c Member Posts: 1
    Well this topic is quite old, but i've had exactly the same problem -

    The solution (from related mibuso posts): set DelayedInsert to Yes on the subform.
Sign In or Register to comment.