Lock Forms to One Object?

So I’ve noticed something weird.

If I call a form from another form - and have it automatically link the item number, then HIDE the item number so it’s not even an option… somehow if I use my mouse’s scroll wheel, it still will save the data I entered and start a new one, called “untitled”.

If I set the form to not allow inserts, it doesn’t work at all, since it still needs to enter once per item number.

Is there any way to make it so you can’t use the scroll wheel/change the record that an active form is viewing?

Don’t quite understand what you mean is weird here.

When you call a form from another form, then the filters you have set will remain active until you remove them in the new form. If you remove the filter, then when exiting and entering the form again, then the same filters will be reset.

And if you have set a filter to field which is not in the form, then creating record will create a new record, but you cannot see it as it filters it out again. If you remove all filters and check what has actually been created in the table then you will see these records.

But setting the InsertAllowed property to No should normally prevent the system from creating new records!

No, what I mean is that if you use the scroll whee, on the mouse, it’ll automatically jump to the next record, even if you already have the item number locked.

The problem with setting InsertAllowed to no is that there isn’t an entry at first, we need to create one. I just want it to ONLY show the entry for THAT item number, no others - similar to how RTC does it.

Ok Danny, then I’ll suggest that you before calling the form verifies that a record exists and if not then creates an entry first. Or you can insert code into the “OnInsert” trigger of the table to use the Item filter as the value for you Item No. field.

If Item No. was one of the primary key fields of the record of the new form, then it would set the Item No. value automatically using the filter.

Yes, Item No. is the only primary key of that table.

The problem is I only want it to create a new entry if the user actually types something in - if they just pop the form open then close it without doing anything, I don’t want it to create a blank line… does that make sense?

Well that could be done by asking the user if he wants to create a new record if none exists.

How would I do that?

I was hoping there was just an easy way using C/AL code to have it save the record only if one of the fields has been modified.

Hi Danny,

I would write a function in the table of the calling form that I would call from the form. I would not code it directly on the form, even though this is also possible. But if I’m later going to upgrade to the RTC then it’s going to be easier if no code exists on forms.

The code would look something like this::

Function LookupNewForm(ItemNo)


IF NOT NewRecord.GET(ItemNo) THEN
IF CONFIRM(Text5000,TRUE) THEN BEGIN
CLEAR(NewRecord);
NewRecord."Item No." := ItemNo;
NewRecord.INSERT;

END ELSE
EXIT; // Did not select to create a new

NewRecordForm.SETRECORD(NewRecord);
NewRecordForm.RUNMODAL;

Danny,

Did this solve your problem?