Closing Company

tejateja Member Posts: 78
hi


IS it possible to close company through coding in the form.

I tried calling a function 'Companyclose' from codeunit 1 . I called this function in OnQuerycloseform, But it is not working.

Any suggestions...

Thanks...

Comments

  • MalajloMalajlo Member Posts: 294
    You can send key stroke ALT+F4 using WindowsScriptingHost.

    For closing NAV use:
    Name	DataType	Subtype	Length
    wscript	Automation	'Windows Script Host Object Model'.WshShell	
    
    
    wscript.SendKeys('%{F4}');
    

    search Google for other definitions of keys.
  • sashoksashok Member Posts: 4
    Added this Code,

    wscript.SendKeys('%{F4}');

    It's not working.
    Stays as such. No Implication.

    What shall be the problem?

    Thanks.
  • WaldoWaldo Member Posts: 3,412
    That would be closing the client, no?
    To close the company, you can send the alt-shortcuts, like (in pseudo):
    Send ALT+F (File)
    Send M (Company)
    Send C (Close)

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • sashoksashok Member Posts: 4
    Thanks Waldo for reply.

    But that too seems to be not working.

    Can u get the exact syntax or code for that.

    Considering wscript as the Automation variable of type
    'Windows Script Host Object Model'.WshShell


    Thanks
  • WaldoWaldo Member Posts: 3,412
    You'll have to see which language you're working in. My pseudo works in English with this code:
    IF ISCLEAR(wsShell) THEN
      CREATE(wsShell);
    
    wsShell.SendKeys('%{f}');
    wsShell.SendKeys('{m}');
    wsShell.SendKeys('{c}');
    
    If working with multiple languages, I tried switching languages like this:
    IF ISCLEAR(wsShell) THEN
      CREATE(wsShell);
    
    intCurrentLanguage := GLOBALLANGUAGE;
    GLOBALLANGUAGE := 1033;
    
    wsShell.SendKeys('%{f}');
    wsShell.SendKeys('{m}');
    wsShell.SendKeys('{c}');
    
    GLOBALLANGUAGE := intCurrentLanguage;
    
    But that didn't work - so don't use the code above!

    May be just create something like: (I also added F12 in front, because the menu behaves differently when you're in a certain form or object designer. With F12, you're sure you're in the menu - so always in the same "state")
    IF ISCLEAR(wsShell) THEN
      CREATE(wsShell);
    
    CASE GLOBALLANGUAGE OF
      1033:   //ENU
        BEGIN
          wsShell.SendKeys('{F12}');
          wsShell.SendKeys('%{f}'); //ALT+F
          wsShell.SendKeys('{m}');
          wsShell.SendKeys('{c}');
        END;
      2067:   //NLB
        BEGIN
          wsShell.SendKeys('{F12}');
          wsShell.SendKeys('%{b}');  //ALT+B
          wsShell.SendKeys('{j}');
          wsShell.SendKeys('{s}');
        END;
      2060:   //FRB
        BEGIN
          wsShell.SendKeys('{F12}');
          wsShell.SendKeys('%{f}');  //ALT+F
          wsShell.SendKeys('{o}');   //In case of French ... two times "o" has to be sent
          wsShell.SendKeys('{f}');
        END;
    END;
    

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • sashoksashok Member Posts: 4
    Thanks Waldo.

    The Code is working perfectly.

    My Scenario is I have to call this in Codeunit 1 - Application Management.

    i.e., When Opening a company, Check for some conditions and if not satisfied, Close the Company.

    Where to place the Code.

    I placed the Code in CompanyOpen, the Code is getting executed, and after that the Company gets Opened which should not happen.

    Pls Help.
  • sergisoftsergisoft Member Posts: 37
    It is working correctly for me, but there is one way that is not working on my test:

    When I select the company from the company selection window (after do F12), It always work except when I select the company by doing a double-click. Making an enter-key works, pressing accept button works but never works when I use double-click. ](*,)

    I am using NAV 2009 SP1 on a remote desktop computer with windows server 2003.

    Thank you!

    Sergi Navarro

    MCTS: Microsoft Dynamics™ NAV 2009 C/SIDE Solution Development

    Visit my Navision Spanish Blog here: http://www.sergisoft.com
  • sergisoftsergisoft Member Posts: 37
    8) Solved:
    Now I am using a sleep(1000) before the first sendkeys call.
    I think that now NAV is having enought time for closing the company selection window so sendKeys are fired on NAV window and not on the company selection window.

    Sergi Navarro

    MCTS: Microsoft Dynamics™ NAV 2009 C/SIDE Solution Development

    Visit my Navision Spanish Blog here: http://www.sergisoft.com
Sign In or Register to comment.