VBA Developer's Guide

Transcription

Microsoft Dynamics GPVBA Developer’s GuideRelease 9.0

CopyrightCopyright 2005 Microsoft Corporation. All rights reserved.Complying with all applicable copyright laws is the responsibility of the user. Without limiting therights under copyright, no part of this document may be reproduced, stored in or introduced into aretrieval system, or transmitted in any form or by any means (electronic, mechanical,photocopying, recording, or otherwise), or for any purpose, without the express written permissionof Microsoft Corporation. Notwithstanding the foregoing, the licensee of the software with whichthis document was provided may make a reasonable number of copies of this document solely forinternal use.TrademarksMicrosoft, Excel, Microsoft Dynamics, Outlook, Visual Basic, and Windows are either registeredtrademarks or trademarks of Microsoft Corporation or its affiliates in the United States and/or othercountries. FairCom and c-tree Plus are trademarks of FairCom Corporation and are registered in theUnited States and other countries.The names of actual companies and products mentioned herein may be trademarks or registeredmarks - in the United States and/or other countries - of their respective owners.Unless otherwise noted, the example companies, organizations, products, domain names, e-mailaddresses, logos, people, places, and events depicted herein are fictitious. No association with anyreal company, organization, product, domain name, e-mail address, logo, person, place, or event isintended or should be inferred.Intellectual propertyMicrosoft may have patents, patent applications, trademarks, copyrights, or other intellectualproperty rights covering subject matter in this document. Except as expressly provided in anywritten license agreement from Microsoft, the furnishing of this document does not give you anylicense to these patents, trademarks, copyrights, or other intellectual property.Warranty disclaimerMicrosoft Corporation disclaims any warranty regarding the sample code contained in thisdocumentation, including the warranties of merchantability and fitness for a particular purpose.Limitation of liabilityThe content of this document is furnished for informational use only, is subject to change withoutnotice, and should not be construed as a commitment by Microsoft Corporation. MicrosoftCorporation assumes no responsibility or liability for any errors or inaccuracies that may appear inthis manual. Neither Microsoft Corporation nor anyone else who has been involved in the creation,production or delivery of this documentation shall be liable for any indirect, incidental, special,exemplary or consequential damages, including but not limited to any loss of anticipated profit orbenefits, resulting from the use of this documentation or sample code.License agreementUse of this product is covered by a license agreement provided with the software product. If youhave any questions, please call the Microsoft Dyamics GPCustomer Assistance Department at 800456-0025 (in the U.S. or Canada) or 1-701-281-6500.Publication dateJune 2006

ContentsIntroduction . 2What’s in this manual . 2Prerequisites . 2Product support . 3Symbols and conventions. 3What’s next . 4Part 1: Using VBA . 6Chapter 1: VBA Overview . 7The Visual Basic Editor . 7The VBA project . 8Objects . 10Programming model . 12Using VBA with the Modifier . 13Online help . 14Multiple third-party products. 14Chapter 2: Programming Windows . 15Working with windows in a VBA project . 16Programming a window object . 17Using window events . 18Window open events. 19Window close events. 20Window activate events. 21Modal dialog events . 22Using window properties and methods. 24Chapter 3: Programming Window Fields . 31Working with window fields in your VBA project. 32Programming a window field object . 34Using window field events . 35Got focus events. 36User changed events . 38VBADEVELOPER’SGUIDEi

C O N T E N T SChanged event. 40Lost focus events . 41Using window field properties and methods . 43Working with field values. 47Verifying field values. 51Window field type reference . 54Chapter 4: Programming Grids . 73Working with grids in your VBA project. 74Programming a grid object . 76Types of grids. 77Using grid events . 78Using grid properties and methods . 82Chapter 5: Programming Reports . 83Working with reports in your VBA project . 83Using report events. 85Start/End events . 86Band events . 87Using report properties and methods. 91Working with report fields . 92Exporting data to other applications. 95Chapter 6: Storing Additional Data . 97Understanding the DUOS. 97Structure of the DUOS. 98Working with DUOS data objects. 100Retrieving a DUOS data object. 101Deleting a DUOS data object . 101Updating a DUOS data object . 101DUOS properties and methods. 102Using the DUOS . 103Chapter 7: Distributing a Project . 113Enabling VBA .113References to external components .113Distributing project files.115iiV B AD E V E L O P E R ’SG U I D E

C O N T E N T SPackage files . 116Package file import/export issues . 119Part 2: VBA Object Library . 122Chapter 8: Window Object . 123Activate method. 124AfterActivate event . 125AfterClose event . 126AfterModalDialog event. 127AfterOpen event . 130BeforeActivate event . 131BeforeClose event . 132BeforeModalDialog event. 133BeforeOpen event . 136Caption property . 137Changed property. 138Close method. 139EventMode property . 140Height property . 142Hide method . 143IsLoaded property . 144Left property . 145Move method . 146Name property . 147Open method. 148PullFocus method . 150Required property . 152Show method . 153Top property . 154Visible property . 155Width property . 157Chapter 9: Field Object . 159AfterGotFocus event . 160AfterLostFocus event . 161AfterUserChanged event. 162BeforeGotFocus event . 163BeforeLostFocus event . 164BeforeUserChanged event. 165Caption property . 167Changed event . 168Empty property. 170Enabled property . 171Focus method . 172FocusSeg method . 173VBADEVELOPER’SGUIDEiii

C O N T E N T SHeight property . 175Left property . 176Locked property . 177Move method . 178Name property . 179Object property. 180Parent property. 182Required property. 183TabStop property. 184Top property . 185Value property . 186ValueSeg property. 189Visible property . 190Width property . 191Chapter 10: Grid Object . 193AfterLineChange event . 194AfterLineGotFocus event . 195AfterLineLostFocus event. 196BeforeLineChange event . 197BeforeLineGotFocus event . 198BeforeLineLostFocus event. 199BeforeLinePopulate event. 200Changed property . 201EventMode property . 202Hide method . 203Left property . 204Move method . 205Name property . 207Show method . 208Top property . 209Visible property . 210Chapter 11: Report Object . 211BeforeAF event . 212BeforeAH event . 213BeforeBody event . 214BeforePF event. 215BeforePH event. 216BeforeRF event. 217BeforeRH event. 218Cancel method. 219End event. 220EventMode property . 221Legend property. 222Name property . 223Start event. 224ivV B AD E V E L O P E R ’SG U I D E

C O N T E N T SChapter 12: VBAGlobal Object. 225DUOSObjectCombineID method . 226DUOSObjectExtractID method. 228DUOSObjectsGet method. 230Chapter 13: DUOSObjects Collection . 233Exists property . 234Item property. 235Name property. 236Remove method . 237SortByExisting property . 238Chapter 14: DUOSObject Object . 241ID property . 242Properties property. 243Chapter 15: DUOSProperties Collection. 245Count property. 246Exists property . 247Item property. 248Remove method . 250Chapter 16: DUOSProperty Object . 251Name property. 252Value property. 253Appendix . 256Appendix A: VBA Errors . 257Handling VBA errors . 257VBA error reference. 258Glossary . 265Index. 269VBADEVELOPER’SGUIDEv

viV B AD E V E L O P E R ’SG U I D E

INTRODUCTION

IntroductionMicrosoft Visual Basic for Applications, or VBA, is a standardprogramming language used by Microsoft Office products, as well as bymany other software providers who choose to embed VBA. Applicationssuch as Microsoft Dynamics GP host VBA as part of the Modifier. Thetools available in the VBA environment allow you to customize windows,fields and reports. In addition, you can attach VBA code to fields you createusing the Modifier.What’s in this manualThe VBA Developer’s Guide is designed to teach the basics of using VBAwith Microsoft Dynamics GP. The manual is divided into the followingparts: Part 1, Using VBA, provides information on how you can programwindows, window fields, grids and reports, as well as store additionalapplication data. Part 2, VBA Object Library, provides reference information aboutproperties, methods and events for objects in Microsoft Dynamics GP.PrerequisitesKeep in mind that VBA is a powerful programming language, and a basicknowledge of VBA programming concepts is required. If you haven’tworked with VBA before, we strongly recommend you review one of themany books available that discuss programming with VBA.The remainder of the manual assumes that you are already familiar withVBA’s programming concepts and features, as well as Microsoft DynamicsGP. It explains how to use your existing VBA knowledge to work with theVBA capabilities available with the accounting system.2V B AD E V E L O P E R ’SG U I D E

IN TRO DUCT IO NProduct supportTechnical support for VBA can be accessed by the following methods: Telephone support – Technical Support at (888) 477-7877 between 8:00a.m. and 5:00 p.m. Central Time, Monday through Friday. Internationalusers can contact Technical Support at (701) 281-0555. Internet – VBA Technical Support is also available online throughCustomerSource or PartnerSource, and is accessible fromwww.microsoft.com/businesssolutions.Symbols and conventionsTo help you use the VBA documentation more effectively, we’ve used thefollowing symbols and conventions within the text to make specific types ofinformation stand out.SymbolDescriptionThe light bulb symbol indicates helpful tips,shortcuts and suggestions.Warnings indicate situations you should beespecially aware of.Margin notes summarizeimportant information.Margin notes call attention to criticalinformation, and direct you to other areas ofthe documentation where a topic is explained.ConventionDescriptionPart 1, Using VBABold type indicates a part name.Chapter 1, “VBAOverview”Quotation marks indicate a chapter name.Setting window fieldsItalicized type indicates a section name.set 'l Item' to 1.This font is used for VBA code examples.RUNTIME.EXEWords in uppercase indicate a file name.Visual Basic forApplications (VBA)Acronyms are spelled out the first time they’reused.TABor ALT MSmall capital letters indicate a key or a keysequence.VBADEVELOPER’SGUIDE3

I N T R O D U C T I O NWhat’s nextBefore you can begin using VBA, be sure to complete the following tasks:1. Install Microsoft Dynamics GP.The runtime engine available with Microsoft Dynamics GP includes thecomponents necessary to support the VBA environment.2. Register the Modifier.To activate the VBA environment, you must register the Modifier. Theregistration keys to register the Modifier are supplied with theaccounting system. Once you’ve registered the Modifier, you can accessthe Visual Basic environment from the Tools menu.3. Review Chapter 1, “VBA Overview”.This chapter explains the basics of how the accounting systemintegrates with the Visual Basic environment. Once you’ve reviewedthe information in this chapter,

Microsoft Visual Basic for Applications, or VBA, is a standard programming language used by Microsoft Office products, as well as by many other software providers who choose to embed VBA. Applications such as Microsoft Dynamics GP host VBA as part of the Modifier. The tools available in the VBA environment allow you to customize windows,