Return selected record after FORM.RUN

In the OnLookup trigger of a TextBox, I am starting another form using FORM.RUN. I am doing it here so that filters can be passed. How do I pass the selected record back to populate the field of the TextBox?

This is the code: IF FORM.RUN(FORM::,) = ACTION::LookupOK THEN MyField := .Field; that is: if the user press Ok in the form, then the variable you passed to the form, contains the record on which the user was positioned when he pressed the ok button. Hope this helps you, Marco

quote:


Originally posted by BrianDeaton
In the OnLookup trigger of a TextBox, I am starting another form using FORM.RUN. I am doing it here so that filters can be passed. How do I pass the selected record back to populate the field of the TextBox?


You have to use RUNMODAL, which returns an Action value. If the RUNMODAL function returns ACTION::LookupOK then the User selected a Record. How to get this record depends on how you are calling the Form. If it is defined as a variable you can get the record using Form.GETRECORD. If you are using FORM.RUNMODAL(FORM::Form,Rec) then it is already in the Rec variable. But can’t you define the TableRelation property on the TextBox? You wouldn’t need to use any code then.

Marco and Nelson, I used this code in the trigger OnLookup, and it worked. IF FORM.RUNMODAL(,) = ACTION::LookupOK THEN MyField := .Field; The lookup form is custom for the table. It would not go to this form for some reason when setting the textbox property LookupFormId to it. So, I tried using code .RUN with the TableRelation formatted. The filters worked, but it did not bring back the selected value. Using code to pass the filters and run the form works. Thanks, Brian

Form.RUN will never be able to return a result: Since the calling routine (form, codeunit etc.) will continue execution, and there is no “FormClosed” event that could be handled, there is no way for the calling routine to keep track of when the form was closed and to retrieve a result. Form.RUNMODAL, however, will block the calling routine’s execution until the form has been closed, so the calling routine knows exactly when it is safe to continue and can retrieve the result.

Sorry for my wrong reply: was made at 10pm, just [|)] before spleeping!!

quote:


Originally posted by nelson
You have to use RUNMODAL, which returns an Action value. If the RUNMODAL function returns ACTION::LookupOK then the User selected a Record. How to get this record depends on how you are calling the Form. If it is defined as a variable you can get the record using Form.GETRECORD. If you are using FORM.RUNMODAL(FORM::Form,Rec) then it is already in the Rec variable. But can’t you define the TableRelation property on the TextBox? You wouldn’t need to use any code then.