How compare a date on close a form

markyTmarkyT Member Posts: 120
Dear folks, I need to compare a date with a date field but I've problems. Simply, in a form, oncloseform, i want to compare "Order Date" field with 12/10/12 date. If "Order Date" field is< than this date you can go out the form, else show a message. How can I do it, please?.
Thaks for help.

Comments

  • postsauravpostsaurav Member Posts: 708
    Hi Marky,

    Hope this is what you are looking for..
    OBJECT Form 50001 Close Form
    {
      OBJECT-PROPERTIES
      {
        Date=12-11-12;
        Time=[ 8:24:27 PM];
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=9790;
        Height=6490;
        SourceTable=Table39;
        OnCloseForm=BEGIN
                      IF "Order Date" >= 121012D THEN BEGIN
                        MESSAGE('You Cannot CLose the Form');
                        FORM.RUNMODAL(50001,Rec);
                      END;
                    END;
    
      }
      CONTROLS
      {
        { 1102153000;TabControl;220;220 ;9350 ;5280 ;HorzGlue=Both;
                                                     VertGlue=Both;
                                                     PageNamesML=ENU=General }
        { 1102153001;TextBox;3850 ;990  ;2750 ;440  ;ParentControl=1102153000;
                                                     InPage=0;
                                                     SourceExpr="Document Type" }
        { 1102153002;Label  ;440  ;990  ;3300 ;440  ;ParentControl=1102153001 }
        { 1102153003;TextBox;3850 ;1540 ;2750 ;440  ;ParentControl=1102153000;
                                                     InPage=0;
                                                     SourceExpr="Document No." }
        { 1102153004;Label  ;440  ;1540 ;3300 ;440  ;ParentControl=1102153003 }
        { 1102153005;TextBox;3850 ;2090 ;2750 ;440  ;ParentControl=1102153000;
                                                     InPage=0;
                                                     SourceExpr=Type }
        { 1102153006;Label  ;440  ;2090 ;3300 ;440  ;ParentControl=1102153005 }
        { 1102153007;TextBox;3850 ;2640 ;2750 ;440  ;ParentControl=1102153000;
                                                     InPage=0;
                                                     SourceExpr="No." }
        { 1102153008;Label  ;440  ;2640 ;3300 ;440  ;ParentControl=1102153007 }
        { 1102153009;TextBox;3850 ;3190 ;1700 ;440  ;ParentControl=1102153000;
                                                     InPage=0;
                                                     SourceExpr="Order Date" }
        { 1102153010;Label  ;440  ;3190 ;3300 ;440  ;ParentControl=1102153009 }
        { 1102153011;CommandButton;7370;5720;2200;550;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     PushAction=FormHelp }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    

    Let me know if this is what you were looking for.

    In above form i created a new form based on table 39 and on close form i have written below piece of code..
    IF "Order Date" >= 121012D THEN BEGIN
      MESSAGE('You Cannot CLose the Form');
      FORM.RUNMODAL(50001,Rec);
    END;
    

    Thanks & Regards,
    Saurav Dhyani

    Do you Know this About NAV?


    Connect - Twitter | Facebook | Google + | YouTube

    Follow - Blog | Facebook Page | Google + Page
  • markyTmarkyT Member Posts: 120
    Thanks for reply. It was like:
    IF "Order Date" >= 121012D THEN BEGIN
    MESSAGE('You Cannot CLose the Form');
    FORM.RUNMODAL(50001,Rec);
    END;

    How easy when you know it!!! :D Thanks for help!!.
  • postsauravpostsaurav Member Posts: 708
    welcome \:D/ \:D/

    Thanks & Regards,
    Saurav Dhyani

    Do you Know this About NAV?


    Connect - Twitter | Facebook | Google + | YouTube

    Follow - Blog | Facebook Page | Google + Page
  • ppavukppavuk Member Posts: 334
    the right way to do such things is
    onquerycloseform
    IF "Order Date" >= 121012D THEN BEGIN
      Error('You Cannot CLose the Form');
    END;
    

    this will prevent form to be closed, so you don't need to re-run it. And all scope (globals) would also remain unchanged until condition is met and form is closed.
  • kinekine Member Posts: 12,562
    Ok, what prevents me to go to next order and close the form from there? Such a checks on "closing" form is not the correct way to do something. It will give you only new problems.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    & what happens after 12/10/12 - are you going to keep manually adjusting the date in the code?

    What was the root problem that makes you want to do this?
    Perhaps if we understand WHY, we can offer a better solution.

    Is it a posting date problem?
    Or are you trying to deal with older orders from being forgot?
Sign In or Register to comment.