In the OnAfterInput trigger for your text box you can call the MakeDateText function in codeunit 1. Pass it the Text parameter that comes with this trigger.
1. Declare a record variable that has a field datatype Date in it. Lets say we use the Date record as variable recDate.
2. Declare a text variable for your TextBox to act as Standard NAV date Filter. Lets use myTextDate.
3. Put myTextDate on the SourceExpr property of your textbox.
4. On the validate trigger of your textbox. Put the code like this.
Note : If you input the character listed below in the textbox:
M = Will return the date of Monday in the current week.
T = Will return the date of Tuesday in the current week.
W = Will return the date of Wednesday in the current week.
TH = Will return the date of Tuesday in the current week.
F = Will return the date of Friday in the current week.
S = Will return the date of Saturday in the current week.
SU = Will return the date of Sunday in the current week.
If you want to capture the character 'T' as today or 'W' as workdate then you must have a LONG code like this.
myTextDate := UPPERCASE(myTextDate);
//---- Make TU as Tuesday
IF STRPOS(myTextDate, 'TU') > 0 THEN BEGIN
recDate.SETFILTER("Period Start", 'T');
IF STRLEN(myTextDate) <> 2 THEN BEGIN
WHILE STRPOS(myTextDate, 'TU') <> 0 DO BEGIN
myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'TU') - 1) +
recDate.GETFILTER("Period Start") +
COPYSTR(myTextDate, STRPOS(myTextDate, 'TU') + 2, STRLEN(myTextDate));
END;
END ELSE
myTextDate := recDate.GETFILTER("Period Start");
END;
//---- Make WE as Wednesday
IF STRPOS(myTextDate, 'WE') > 0 THEN BEGIN
recDate.SETFILTER("Period Start", 'W');
IF STRLEN(myTextDate) <> 2 THEN BEGIN
WHILE STRPOS(myTextDate, 'WE') <> 0 DO BEGIN
myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'WE') - 1) +
recDate.GETFILTER("Period Start") +
COPYSTR(myTextDate, STRPOS(myTextDate, 'WE') + 2, STRLEN(myTextDate));
END;
END ELSE
myTextDate := recDate.GETFILTER("Period Start");
END;
//---- for the character T as TODAY
IF STRPOS(myTextDate, 'T') > 0 THEN BEGIN
IF STRLEN(myTextDate) <> 1 THEN BEGIN
WHILE STRPOS(myTextDate, 'T') <> 0 DO BEGIN
myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'T') - 1) +
FORMAT(TODAY) +
COPYSTR(myTextDate, STRPOS(myTextDate, 'T') + 1, STRLEN(myTextDate));
END;
END ELSE
myTextDate := FORMAT(TODAY);
END;
//---- for the character W as WORKDATE
IF STRPOS(myTextDate, 'W') > 0 THEN BEGIN
IF STRLEN(myTextDate) <> 1 THEN BEGIN
WHILE STRPOS(myTextDate, 'W') <> 0 DO BEGIN
myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'W') - 1) +
FORMAT(WORKDATE) +
COPYSTR(myTextDate, STRPOS(myTextDate, 'W') + 1, STRLEN(myTextDate));
END;
END ELSE
myTextDate := FORMAT(WORKDATE);
END;
recDate.SETFILTER("Period Start", myTextDate);
myTextDate := recDate.GETFILTER("Period Start");
Thanks to jreynolds for his post that got me going in the right direction. I have a report where I have a text box on the options tab, and I want that text box to work as a date and recieve date ranges and values such as "t", "y-1", etc. Instead of using MakeDateText, I found MakeDateFilter in Codeunit1. It works!
Comments
you can make it a date type & convert to text when needed if you like.
http://www.BiloBeauty.com
http://www.autismspeaks.org
thanks savatage
GD
1. Declare a record variable that has a field datatype Date in it. Lets say we use the Date record as variable recDate.
2. Declare a text variable for your TextBox to act as Standard NAV date Filter. Lets use myTextDate.
3. Put myTextDate on the SourceExpr property of your textbox.
4. On the validate trigger of your textbox. Put the code like this.
5. Done.
Note : If you input the character listed below in the textbox:
M = Will return the date of Monday in the current week.
T = Will return the date of Tuesday in the current week.
W = Will return the date of Wednesday in the current week.
TH = Will return the date of Tuesday in the current week.
F = Will return the date of Friday in the current week.
S = Will return the date of Saturday in the current week.
SU = Will return the date of Sunday in the current week.
If you want to capture the character 'T' as today or 'W' as workdate then you must have a LONG code like this.
Hope this works for you too