Control fields on a form

dabba23dabba23 Member Posts: 77
Hi,

I have form 26 and need via another table decide whether fields on the form must be editable or not.

In a new table/form users can select a list of fields from record 23.
When users then open form 26, I need to code that if a field exists in this new table then the field on the form must be editable.

First I have set all the fields to non-editable and on OpenForm I have done following:

OnOpenForm
lv_RecRef.GETTABLE(Rec);
F_ActivateFields(RecRef);

F_ActivateFields(RecRef)(VAR lv_RecRef : RecordRef)
lr_TemplateHeader.SETRANGE(TableID,lv_RecRef.NUMBER);
if lr_TemplateHeader.findfirst then
F_UpdateFields(lr_TemplateHeader,lv_RecRef);

F_UpdateFields(lr_Template : Record Field Template Header; VAR lv_RecRef : RecordRef)
lr_TemplateLine.SETRANGE("Data Template Code",lr_TemplateHeader.Code);
lr_TemplateLine.setrange(Type,TemplateLine.Type::Field);
IF lr_TemplateLine.FINDFirst THEN
REPEAT
IF lr_TemplateLine.FieldID <> 0 THEN BEGIN
[what happens here ???]
END
UNTIL lr_TemplateLine.NEXT = 0;

I am not sure what to do next, so that I can do following on every field on the form:

CurrForm.Name.EDITABLE(true);

Thanks
Ann

Comments

  • krzychub83krzychub83 Member Posts: 120
    HI dabba23

    I prefer to put such code in OnFormat trigger of controls.

    Example:
    Value - OnFormat(VAR Text : Text[1024];)
    IF Value<5 THEN
      CurrForm.Value.UPDATEFORECOLOR(255)
    ELSE
      IF Value>20 THEN
        CurrForm.Value.UPDATEFORECOLOR(65280)
      ELSE
        CurrForm.Value.UPDATEFORECOLOR(0);
    

    You can use:
    CurrForm.Value.UPDATEEDITABLE(TRUE/FALSE);

    GoodLuck
  • kinekine Member Posts: 12,562
    Problem is that there is no dynamic way to access controls on the form. It means that there is no generic way how to do that. You need to create some specific code for each control on the form in design time...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    Are you talking if the vendor # already exists then not-editable??

    Not sure if this is on the same track but I have a start date on the item card. As soon as someone enters a price in the item price tabel I wanted the start-date to no longer be editable.

    So First I added a flowfield to the item card to see if that item # "EXISTS" on the other table, called it "Prices Exist". If it does then the flowfield shows it as checked on the item card. From there I can easily check.

    If "Prices Exist"
    then CurrForm."Start Date".Editable(False)
    Else CurrForm."Start Date".Editable(True);
  • apertierraapertierra Member Posts: 61
    You are using the wrong approach.
    The fields should be "editable" by default, and what you should do is setting them as non-editable when you want them not to be changed. That way if the field is already non-editable (example, a flowfield or a non-editable field or calculation), it won't break with an error when trying to make it editable. Basically... if it's editable, you do nothing. If not, you make it non-editable.

    BTW... on aftergetrecord is your friend to call a function that just sets the fields to editable or not.
Sign In or Register to comment.