web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics SL (Archived)

AP Voucher Date Validation?

(0) ShareShare
ReportReport
Posted on by 475

Hello All,

A user would like to restrict the entered dates on the SL7 FP1 Voucher & Adjustment entry screen to no more than 31 days in the future.  This would prevent some of the ongoing clerical data entry errors.  The restriction should be for Invoice Date and maybe other fields on the screen.

I have not done validation customizations before, only hide/show.  I am also not a programmer.  Below what I know so far.

I experimented in Excel and learned that the integer equivalents for some dates are as follows:

Date Equivalent Difference
1/1/2011 40544
2/1/2011 40575 31
3/1/2011 40603 28
4/1/2011 40634 31
5/1/2011 40664 30
6/1/2011 40695 31
7/1/2011 40725 30
8/1/2011 40756 31

I theorized this would mean that a data entry comparison of the string integer equivalent against a chosen max should allow me to check if exceeded.

I opened Customization Manager | Selected Invoice Date Field | Visual Basic Editor, and entered the following IF "code" into the automatic "Private Sub" which opened as shown below:

Private Sub cinvcdate_Chk(ChkStrg As String, retval As Integer)
If retval > (retval + 31) Then retval = 0
End Sub

I saved and closed the screen.  I entered an Invoice Date 32 days in the future from today (i.e. 6/19/2011) and the screen immediately closed without any messages or processing or saving, just like nothing had happened.

Could someone please help?  Thank you kindly in advance.

-Luis

*This post is locked for comments

I have the same question (0)
  • Barry Flynn Profile Picture
    3,090 on at

    Luis

    I'm not in a position at the moment to wrire (and test!) some sample code.

    But, a few thoughts

    The ChkStrg parameter is a string of the data entered by the operator.

    So you look at it to see what the operator entered.

    The RetVal parameter is a code sent back to the kernel.

    It tells the kernel how to proceed.

    Leave RetVal alone if the newly entered date is OK.

    If it is not OK, do someething like this

     call messbox("date is invalid", mb_ok, "VBA DocDate Editing")

    retval = ErrNoMess

    exit sub

    The screen may be crashing because of illegal values being placed in RetVal.

    To actually validate the date, you can use code something like

     dim ldNow as sDate

     call GetSysDate(ldNow)

    That should populate ldNow with the current date (which may be different from the Business Date.)

    YOu could then use the StringToDate call to convert the chkstrg value (which is a String) into a different sDate variable.

    The DatePlusdays call can be used to add 31 days to the "now" date.

    You could then use the DateCmp function to compare the two dates.

    Hope that helps a little.

    Barry

  • Suggested answer
    Jeff Trotman Profile Picture
    275 on at

    I wrote the code to post and just now saw Barry's earlier reply.  He is exactly right and what he's suggesting is almost exactly what this code does.  Paste this into your Chk event and this should do what you want:

       Dim dtEntered As Sdate

       Dim dtToday As Sdate

       Dim dtTodayPlus31 As Sdate

       'Get entered date

       Call StrToDate(ChkStrg, dtEntered)

       'Get current date

       Call GetBufferValue("bpes.today", dtToday.val)

       'Get day 31 days in the future

       Call DatePlusDays(dtToday, 31, dtTodayPlus31)

       'Compare entered day to future day - DateCmp returns 1 if first date is greater than 2nd date

       If DateCmp(dtEntered, dtTodayPlus31) = 1 Then

           Call MessBox("Date cannot be more than 31 days in the future.", _

               MB_ICONEXCLAMATION, "Error")

           retval = ErrNoMess

       End If

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics SL (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans