Microsoft Dynamics GP Developing for Dynamics GP
A blog dedicated to the Microsoft Dynamics GP Developer & Consultant community
 
Welcome to MSDN Blogs Sign in | Join | Help

Developing for Dynamics GP

by David Musgrave (Australia) and the Microsoft Dynamics GP Developer Support Team (USA)

News

  • Please use the Blog Feedback? - Contact Us link at the top of the page to email questions relating to the blog itself.

    If you wish to ask a technical question, please use the links below to ask on the Newsgroups. If you ask on the Newsgroups, others in the community can respond and the answers are available for everyone in the future.

    Please do not use comments on pages and posts to ask questions unrelated to the topic on that page or post.



    Dates of Interest:

    11-Jul-2008: Blog Created by David Musgrave.
    10-Oct-2008: First Post by Scott Stephenson.
    04-Nov-2008: First Post by Dave Dusek.
    11-Nov-2008: First Post by Beth Gardner.
    28-Nov-2008: First Post by Chris Roehrich.
    30-Dec-2008: First Post by Patrick Roth.
    24-Feb-2009: First Post by Greg Willson.
    22-Apr-2009: First Post by David Clauson.
    04-May-2009: First Post by Ryan Wigestrand.
    19-Jun-2009: First Post by Dawn Langlie.
    03-Jul-2009: First Post by Emily Halvorson.
    23-Sep-2009: Created Twitter account with blog feed.



    WorldMaps Statistics since
    24-Feb-2009:




    Click for WorldMaps Stumbler



    Translator Tool:




    Social Networking

    Follow David Musgrave and the blog on:

    David Musgrave on Twitter

    David Musgrave on LinkedIn


    Disclaimer

    This blog is provided "AS IS" with no warranties, and confers no rights.

    The links in this blog may lead to third-party Web sites. Microsoft provides third-party resources to help you find customer service and/or technical support resources. Information at these sites may change without notice. Microsoft is not responsible for the content at any third-party Web sites and does not guarantee the accuracy of third-party information.

Contents

Favourite Posts

Blog Links

Newsgroups Links

Resources Links

VBA - Preventing backdated transactions using Visual Basic

David MeegoAnother recent request was to provide a method to prevent backdated transactions from being entered into Microsoft Dynamics GP.  This means that we needed to validate the document date of a transaction as it as entered and again when it is saved. This is a perfect opportunity to demonstrate how Visual Basic for Applications (VBA) can add custom business rules to the application.

Note: If you want to take it one step further, you can check the transaction dates before attempting to post a batch of transactions. This is possible with VBA but would require the use of ADO (ActiveX Data Objects) to access the SQL data to validate the transactions in a given batch.  This post will not be covering this additional level of complexity.


Below is summary of the steps used to add the business rules to the Sales Order Processing Sales Transaction Entry window:

  1. Selected Transactions >> Sales >> Sales Transaction Entry to open the window.
     
  2. Selected Tools >> Customise >> Add Current Window to Visual Basic.
     
  3. Selected Tools >> Customise >> Add Fields to Visual Basic.
     
  4. Clicked on the Save Button and the Date field to add them to VBA.
     
  5. Selected Tools >> Customise >> Add Fields to Visual Basic to disable the selection tool (You can also press Escape).
     
  6. Selected Tools >> Customise >> Visual Basic Editor.
     
  7. Optional but recommended, only needs to be performed once on a workstation. Select Tools >> Options and on the editor tab, check the Require Variable Declaration option.
     
  8. Located Microsoft Dynamics GP >> SalesTransactionEntry in the Project window.
     
  9. Double clicked on SalesTransactionEntry module.
     
  10. In the Properties window, selected Date.
     
  11. Changed the name property from Date to DocDate as Date is a keyword in VBA.
     
  12. Wrote the code for the 3 events (see below).
     
  13. Selected Debug >> Compile Microsoft Dynamics GP.
     
  14. Selected File >> Save Microsoft Dynamics GP.
     
  15. Selected File >> Close and Return to Microsoft Dynamics GP.

The code needs to handle 3 events.  The first event is when the user changes the Document Date field.  The second and third events handle when the document is saved, both when the Save Button is pressed and also when save is selected from the "Do you want to save or delete the document?" dialog.

SalesTransactionEntry VBA Code

Note: The text for the PromptString in the Select Case statement in the Window_BeforeModalDialog() event will need to be adjusted to match the text for the transaction entry window where the code is being used.

An example package of the v10.0 Sales Transaction Entry window is attached at the bottom of the article. 

Hope you found this example useful.

David

Posted: Friday, May 08, 2009 9:00 AM by David Musgrave
Filed under:

Attachment(s): SOP Transaction Entry.zip

Comments

DynamicAccounting.net said:

Sweeeet! David Musgrave shows how to prevent entry of a backdated transaction using VBA . There are few

# May 8, 2009 12:09 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker