Semi-automatic Date Picker on every Date field - in 3 steps

WaldoWaldo Posts: 3,412Member
edited 2012-04-27 in NAV Tips & Tricks
I know I know .. Probably all of you already implemented it, but for those who didn't … here's how :)

Probably everybody knows the functionality when putting a question mark ('?') into a text field, that the standard text functionality pops up?

Well, I've got an easy-to-create variant of this for dates.

What do you have to do?

1. Download the Date Time Picker from Mibuso: http://www.mibuso.com/dlinfo.asp?FileID=563 (thanks Woody)
2. Import it in your database (obviously you don't need the sample form)
3. Add this code to codeunit 1 in trigger "MakeDateText" (create a local variable of the type "form" for your Date Picker":
IF DateText IN ['?',' '] THEN BEGIN
  lfrmDatePicker.SetCurrDate(TODAY);
  lfrmDatePicker.LOOKUPMODE(TRUE);
  IF lfrmDatePicker.RUNMODAL = ACTION::LookupOK THEN BEGIN
    DateText := FORMAT(lfrmDatePicker.GetCurrDate);
  END;
END;

It might be that you have to restart your client.

Now just put a ' ' or a '?' into a date field and there is your date picker.

Enjoy!

Eric Wauters
MVP - Microsoft Dynamics NAV
My blog

Comments

  • Luc_Van_DyckLuc_Van_Dyck WilrijkPosts: 3,624Member, Moderator, Administrator
    Excellent tip! It's almost an MVT (Most Valuable Trick) ;-)
    No support using PM or e-mail - Please use this forum. || Search is your friend
    NAV TechDays 2016: 17 & 18 November 2016, Antwerp (Belgium)
  • Mark_BrummelMark_Brummel Posts: 4,244Member, Moderators Design Patterns
    In the past I remember using the Monthly Calendar (7609) form for this.

    It is a brilliant matrixform to pick dates and available in almost every navision database.

    Just add an OK button on it and return the selected date when pushed.
  • WaldoWaldo Posts: 3,412Member
    Indeed, but do you know which granule is needed for this form?

    Anyway, for the OK button: this will give you the selected date:

    "Period Start" + DATE2DWY(CurrForm.Matrix.MatrixRec."Period Start",1) - 1

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Posts: 9,147Member
    The granules are

    3,360 Sales & Receivables - Calendars
  • tompynationtompynation Posts: 398Member
    How do you guys do this with the Monthly Calendar control?

    I added this in the MakeDateText trigger of CodeUnit 1.
    lfrmDatePicker is now a variable of Form "Monthy Calendar".

    IF DateText IN THEN BEGIN
    // lfrmDatePicker.SetCurrDate(TODAY);
    lfrmDatePicker.LOOKUPMODE(TRUE);
    IF lfrmDatePicker.RUNMODAL = ACTION::LookupOK THEN BEGIN

    END;
    END;

    How do you add the return value to the OK button?
    The pushaction of my button is LookupOK

    But where do you add the line: "Period Start" + DATE2DWY(CurrForm.Matrix.MatrixRec."Period Start",1) - 1
    Is this the RunCommand?

    Cause i cannot get it to work the return the selected date
  • tompynationtompynation Posts: 398Member
    allright, got it working
  • lgplgp Posts: 77Member
    Hi - I am trying out the Date Picker in NAV2009R2. After selecting a date with the Date Picker, if I go directly to the next date field and type '?', I get an error: "The form has been run. Use the function CLEAR(Form)". Has this been reported, and is there a fix? Thanks...
    Leanne G. Paul
    Business Applications/IT Advisor, Competitive Edge Services
  • ara3nara3n Posts: 9,147Member
    you need to add the following line.

    clear(lfrmDatePicker.) ; //new line.
    lfrmDatePicker.SetCurrDate(TODAY);
  • lgplgp Posts: 77Member
    Thanks!
    Leanne G. Paul
    Business Applications/IT Advisor, Competitive Edge Services
Sign In or Register to comment.