VBA Developer's Guide

Microsoft Dynamics? GP 2013

VBA Developer's Guide

Copyright

Copyright ? 2012 Microsoft Corporation. All rights reserved.

Limitation of liability

This document is provided "as-is". Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it.

Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred.

Intellectual property

This document does not provide you with any legal rights to any intellectual property in any Microsoft product.

You may copy and use this document for your internal, reference purposes.

Trademarks

Microsoft, Excel, Microsoft Dynamics, Outlook, Visual Basic, Windows, and Windows Vista are trademarks of the Microsoft group of companies. FairCom and c-tree Plus are trademarks of FairCom Corporation and are registered in the United States and other countries.

All other trademarks are property of their respective owners.

Warranty disclaimer

Microsoft Corporation disclaims any warranty regarding the sample code contained in this documentation, including the warranties of merchantability and fitness for a particular purpose.

License agreement

Use of this product is covered by a license agreement provided with the software product. If you have 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 date

September 2012

Contents

Introduction ................................................................................................................................................. 2

What's in this manual...................................................................................................................................2 Prerequisites................................................................................................................................................... 2 Product support ............................................................................................................................................2 Symbols and conventions ............................................................................................................................3 What's next ....................................................................................................................................................3

Part 1: Using VBA ................................................................................................................................ 6

Chapter 1: VBA Overview ............................................................................................................. 7

The Visual Basic Editor ................................................................................................................................7 The VBA project ............................................................................................................................................8 Objects ............................................................................................................................................................9 Programming model .................................................................................................................................. 11 Using VBA with the Modifier ...................................................................................................................12 Online help...................................................................................................................................................12 Multiple third-party products...................................................................................................................12

Chapter 2: Programming Windows ................................................................................... 13

Working with windows in a VBA project ...............................................................................................13 Programming a window object.................................................................................................................14 Using window events.................................................................................................................................15 Window open events ..................................................................................................................................15 Window close events ..................................................................................................................................16 Window activate events .............................................................................................................................17 Modal dialog events ...................................................................................................................................17 Using window properties and methods..................................................................................................19

Chapter 3: Programming Window Fields ..................................................................... 23

Working with window fields in your VBA project ................................................................................23 Programming a window field object........................................................................................................24 Using window field events........................................................................................................................25 Got focus events ..........................................................................................................................................26 User changed events...................................................................................................................................27 Changed event.............................................................................................................................................29 Lost focus events .........................................................................................................................................29 Using window field properties and methods.........................................................................................31 Working with field values .........................................................................................................................33 Verifying field values..................................................................................................................................36 Window field type reference .....................................................................................................................39

Chapter 4: Programming Grids ............................................................................................. 55

Working with grids in your VBA project ................................................................................................55 Programming a grid object ........................................................................................................................57 Types of grids ..............................................................................................................................................58

VBA DEVELOPER'S GUIDE

i

CONTENTS

Using grid events ........................................................................................................................................59 Using grid properties and methods .........................................................................................................62

Chapter 5: Programming Reports....................................................................................... 63

Working with reports in your VBA project .............................................................................................63 Using report events.....................................................................................................................................64 Start/End events .........................................................................................................................................65 Band events..................................................................................................................................................66 Using report properties and methods......................................................................................................69 Working with report fields ........................................................................................................................70 Exporting data to other applications........................................................................................................72

Chapter 6: Storing Additional Data.................................................................................. 75

Understanding the DUOS..........................................................................................................................75 Structure of the DUOS................................................................................................................................76 Working with DUOS data objects.............................................................................................................77 Retrieving a DUOS data object .................................................................................................................78 Deleting a DUOS data object.....................................................................................................................78 Updating a DUOS data object ...................................................................................................................78 DUOS properties and methods.................................................................................................................79 Using the DUOS..........................................................................................................................................80

Chapter 7: Distributing a Project........................................................................................ 87

Enabling VBA ..............................................................................................................................................87 References to external components ..........................................................................................................87 Distributing project files ............................................................................................................................88 Package files.................................................................................................................................................88 Package file import/export issues............................................................................................................91

Part 2: VBA Object Library .................................................................................................. 94

Chapter 8: Window Object ........................................................................................................ 95

Activate method..................................................................................................................................96 AfterActivate event.............................................................................................................................97 AfterClose event..................................................................................................................................98 AfterModalDialog event ....................................................................................................................99 AfterOpen event................................................................................................................................101 BeforeActivate event.........................................................................................................................102 BeforeClose event..............................................................................................................................103 BeforeModalDialog event ................................................................................................................104 BeforeOpen event..............................................................................................................................106 Caption property...............................................................................................................................107 Changed property.............................................................................................................................108 Close method.....................................................................................................................................109 EventMode property ....................................................................................................................... 110 Height property ................................................................................................................................ 111 Hide method ..................................................................................................................................... 112 IsLoaded property ............................................................................................................................ 113 Left property ..................................................................................................................................... 114 Move method .................................................................................................................................... 115 Name property ................................................................................................................................. 116

ii

VBA DEVELOPER'S GUIDE

CONTENTS

Open method..................................................................................................................................... 117 PullFocus method ............................................................................................................................. 118 Required property.............................................................................................................................120 Show method ....................................................................................................................................121 Top property .....................................................................................................................................122 Visible property ................................................................................................................................123 Width property .................................................................................................................................124

Chapter 9: Field Object .............................................................................................................125

AfterGotFocus event.........................................................................................................................126 AfterLostFocus event .......................................................................................................................127 AfterUserChanged event .................................................................................................................128 BeforeGotFocus event.......................................................................................................................129 BeforeLostFocus event .....................................................................................................................130 BeforeUserChanged event ...............................................................................................................131 Caption property...............................................................................................................................132 Changed event...................................................................................................................................133 Empty property .................................................................................................................................134 Enabled property ..............................................................................................................................135 Focus method ....................................................................................................................................136 FocusSeg method ..............................................................................................................................137 Height property ................................................................................................................................138 Left property .....................................................................................................................................139 Locked property................................................................................................................................140 Move method ....................................................................................................................................141 Name property .................................................................................................................................142 Object property..................................................................................................................................143 Parent property .................................................................................................................................144 Required property.............................................................................................................................145 TabStop property...............................................................................................................................146 Top property .....................................................................................................................................147 Value property...................................................................................................................................148 ValueSeg property.............................................................................................................................150 Visible property ................................................................................................................................151 Width property .................................................................................................................................152

Chapter 10: Grid Object............................................................................................................ 153

AfterLineChange event ....................................................................................................................154 AfterLineGotFocus event.................................................................................................................155 AfterLineLostFocus event................................................................................................................156 BeforeLineChange event..................................................................................................................157 BeforeLineGotFocus event ..............................................................................................................158 BeforeLineLostFocus event..............................................................................................................159 BeforeLinePopulate event................................................................................................................160 Changed property.............................................................................................................................161 EventMode property .......................................................................................................................162 Hide method .....................................................................................................................................163 Left property .....................................................................................................................................164 Move method ....................................................................................................................................165 Name property .................................................................................................................................166 Show method ....................................................................................................................................167 Top property .....................................................................................................................................168 Visible property.................................................................................................................................169

Chapter 11: Report Object...................................................................................................... 171

BeforeAF event ..................................................................................................................................172 BeforeAH event .................................................................................................................................173

VBA DEVELOPER'S GUIDE

iii

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download