How to close current form and open another?

Depending on user selection in current form, I want to close the current open form and instead run another. How can this be done? I have tried coding like this: BEGIN FORM.RUN(FORM::“My Form”); CurrForm.CLOSE; END; Then the new form runs as it should. But when currform is closing, the new form is closed as well. [:(!] Any suggestions? Regards Fredrik

What If you do it like this ? Just exchange the lines? CurrForm.CLOSE; FORM.RUN(FORM::“My Form”);

Thanks Koleto, but if you close the card, the execution can not continue.


Originally posted by koleto
What If you do it like this ? Just exchange the lines? CurrForm.CLOSE; FORM.RUN(FORM::“My Form”);

FORM.RUN(FORM::“My Form”); CurrForm.CLOSE;

Hello Nav Nav, did you look at my original question? The problem is that if I do CurrForm.Close, then the form “My Form” is closed as well.

I would guess you have to use RUNMODAL. I made a short test and it worked fine with runmodal and failed with run. in a form i called test1 i had this code on a button: FORM.RUNMODAL(FORM::test2); CurrForm.CLOSE;

yep, didnt read the example from the beggining (or was just thinking for something else :wink: ). Was guessing that you’re managing the whole process from a codeunit. Nos the idea: Given the example you can run the first form from the codeunit ( setting a global variable into the first form to zero for example), then after user makes his choice you can close the form and set this variable to 1 (2,3 depends on the users choice). Then in the codeunit you can safely invoke the second or whichever form you want, based on the value of this variable. If you want to do it from the current form, than you should use .RUNMODAL (in the order you initialy have done that). But then you’ll have two forms open on the screen. Good news is that the user won’t be able to do anything with the “master”(first) form and with the code FORM.RUNMODAL(); CurrForm.CLOSE; after the user closes the second form the “master” (first) form will be closed as well.

Yes, RUNMODAL works fine. The first form remains behind the new form, until the new form is closed. Not the most beautiful solution, but will do. Thankyou guys!

how about: CurrForm.VISIBLE(FALSE); FORM.RUNMODAL(FORM::MyForm); CurrForm.CLOSE; then only MyForm is visible to user, though CurrForm will only be closed after execution of MyForm.

Using visible(false) was interesting. Sometimes I get “Internal error 101 in module 60”. Sometimes all menus close (became invisible?), including the main menu. Sometimes he klient crash. Thanks anyways, Beaver. :slight_smile:

where do you use the call to MyForm? I tried it in an OnPush-Trigger of a commandbutton and that worked perfectly (3.60).

I’m using 3.70. The call to MyForm is placed in the trigger OnNewRecord on a form. Purpose is to catch when user push F3, then an option is presented and depending on the selection, either a new blank card is created as standard, or the current form should be closed and another is opened. Like this: Form - OnNewRecord(BelowxRec : Boolean) Selected := DIALOG.STRMENU(Text003, 1); CASE Selected OF 2: BEGIN FORM.RUNMODAL(FORM::“MyForm”); CurrForm.CLOSE; END; END;

Hi fredrik. Since the new form is a child process of the first it will close when You close the first form. Maybe call a function in a Single Instance Codeunit that open the form?? Havn’t tried it myself. Just an idea…

Hi Lars, thanks for your idea. I have tried it out. Problem is that whatever I call CU or form or whatever, CurrForm.close must be placed below the call line. This means the CurrForm will always have to wait until the call has completed, and then CurrForm can be closed. My dream would ofcourse be if I could catch F3 and redirect it to a CU directly, but the only way I can think of is in the trigger OnNewRecord of the form.

have you tried this one: works also with F3 as shortcut. I was able to popup a MESSAGE (from Separator-OnPush-Trigger)instead of default F3-behavior. Of course we are approaching to the very dark areas of Navision programming now… :slight_smile:

Well… yes it works! Sometimes it’s a very long way to Tipperary, sometimes too far. If I made currform invisible and then made a shortcut for F3, calling a CU, and from this CU do call the new form, then it works. And if user selects the normal behaviour for F3, I could init, GetNextNo and insert and then show the form as supposed to by normal F3 behaviour. But the code would be very hard for someone else to read and understand, or I have to spend a lot of time dokumenting, which someone else then has to spend time reading. I prefer to leave the first form open behind the new one, and then when the new one is closed, the first form will be closed as well. It’s an easy solution… =) Thanks for all help mates!

I had this problem (depending on the contents of the requested record, show 2 different forms) and more or less I solved it this way: FORM #1: ON AFTER GET RECORD IF <use form #2> THEN CurrForm.CLOSE; ON CLOSE FORM IF <use form #2> THEN mycodeunit.RUNDIFFERENTFORM(Rec); END; FORM #2: ON AFTER GET RECORD IF <use form #1> THEN CurrForm.CLOSE; ON CLOSE FORM IF <use form #1> THEN mycodeunit.RUNDIFFERENTFORM(Rec); END; MYCODEUNIT: Function: RUNDIFFERENTFORM(VAR: MyRecord:Record “my record”) IF <use form #1> THEN FORM.RUN(form#1, MyRecord) ELSE FORM.RUN(FORM.RUN(form#1, MyRecord); Hope it helps Ciao, Marco

sorry, in the last line I was meaning: ELSE FORM.RUN(FORM.RUN(form#2, MyRecord); anyway… the key point is that you have to run the other form in the OnClose trigger, AFTER you have launched the FORM.CLOSE. bye