Professional Documents
Culture Documents
VB A Developers Guide
VB A Developers Guide
GP
VBA Developers Guide
Release 9.0
Copyright Copyright 2005 Microsoft Corporation. All rights reserved.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the
rights under copyright, no part of this document may be reproduced, stored in or introduced into a
retrieval system, or transmitted in any form or by any means (electronic, mechanical,
photocopying, recording, or otherwise), or for any purpose, without the express written permission
of Microsoft Corporation. Notwithstanding the foregoing, the licensee of the software with which
this document was provided may make a reasonable number of copies of this document solely for
internal use.
Trademarks Microsoft, Excel, Microsoft Dynamics, Outlook, Visual Basic, and Windows are either registered
trademarks or trademarks of Microsoft Corporation or its affiliates in the United States and/or other
countries. FairCom and c-tree Plus are trademarks of FairCom Corporation and are registered in the
United States and other countries.
The names of actual companies and products mentioned herein may be trademarks or registered
marks - in the United States and/or other countries - of their respective owners.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail
addresses, logos, people, places, and events depicted herein are fictitious. No association with any
real company, organization, product, domain name, e-mail address, logo, person, place, or event is
intended or should be inferred.
Intellectual property Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
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.
Limitation of liability The content of this document is furnished for informational use only, is subject to change without
notice, and should not be construed as a commitment by Microsoft Corporation. Microsoft
Corporation assumes no responsibility or liability for any errors or inaccuracies that may appear in
this 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 or
benefits, resulting from the use of this documentation or sample code.
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 800-
456-0025 (in the U.S. or Canada) or +1-701-281-6500.
Publication date June 2006
V B A D E V E L O P E R S G U I D E i
Contents
Introduction................................................................................................................................. 2
Whats in this manual .................................................................................................................. 2
Prerequisites .................................................................................................................................. 2
Product support ............................................................................................................................ 3
Symbols and conventions............................................................................................................ 3
Whats next .................................................................................................................................... 4
Part 1: Using VBA................................................................................................................ 6
Chapter 1: VBA Overview............................................................................................. 7
The Visual Basic Editor ................................................................................................................ 7
The VBA project ............................................................................................................................ 8
Objects .......................................................................................................................................... 10
Programming model .................................................................................................................. 12
Using VBA with the Modifier................................................................................................... 13
Online help .................................................................................................................................. 14
Multiple third-party products................................................................................................... 14
Chapter 2: Programming Windows................................................................... 15
Working with windows in a VBA project ............................................................................... 16
Programming a window object ................................................................................................ 17
Using window events ................................................................................................................ 18
Window open events.................................................................................................................. 19
Window close events.................................................................................................................. 20
Window activate events............................................................................................................. 21
Modal dialog events ................................................................................................................... 22
Using window properties and methods.................................................................................. 24
Chapter 3: Programming Window Fields..................................................... 31
Working with window fields in your VBA project................................................................ 32
Programming a window field object ....................................................................................... 34
Using window field events ....................................................................................................... 35
Got focus events.......................................................................................................................... 36
User changed events .................................................................................................................. 38
C O N T E N T S
ii V B A D E V E L O P E R S G U I D E
Changed event............................................................................................................................ 40
Lost focus events ........................................................................................................................ 41
Using window field properties and methods........................................................................ 43
Working with field values......................................................................................................... 47
Verifying field values................................................................................................................. 51
Window field type reference .................................................................................................... 54
Chapter 4: Programming Grids............................................................................. 73
Working with grids in your VBA project................................................................................ 74
Programming a grid object ....................................................................................................... 76
Types of grids.............................................................................................................................. 77
Using grid events ....................................................................................................................... 78
Using grid properties and methods ........................................................................................ 82
Chapter 5: Programming Reports....................................................................... 83
Working with reports in your VBA project ............................................................................ 83
Using report events.................................................................................................................... 85
Start/End events ........................................................................................................................ 86
Band events................................................................................................................................. 87
Using report properties and methods..................................................................................... 91
Working with report fields ....................................................................................................... 92
Exporting data to other applications....................................................................................... 95
Chapter 6: Storing Additional Data.................................................................. 97
Understanding the DUOS......................................................................................................... 97
Structure of the DUOS............................................................................................................... 98
Working with DUOS data objects.......................................................................................... 100
Retrieving a DUOS data object............................................................................................... 101
Deleting a DUOS data object .................................................................................................. 101
Updating a DUOS data object ................................................................................................ 101
DUOS properties and methods.............................................................................................. 102
Using the DUOS....................................................................................................................... 103
Chapter 7: Distributing a Project..................................................................... 113
Enabling VBA............................................................................................................................ 113
References to external components ........................................................................................ 113
Distributing project files........................................................................................................... 115
V B A D E V E L O P E R S G U I D E iii
C O N T E N T S
Package files .............................................................................................................................. 116
Package file import/export issues ......................................................................................... 119
Part 2: VBA Object Library.............................................................................. 122
Chapter 8: Window Object..................................................................................... 123
Activate method................................................................................................................ 124
AfterActivate event .......................................................................................................... 125
AfterClose event ............................................................................................................... 126
AfterModalDialog event.................................................................................................. 127
AfterOpen event ............................................................................................................... 130
BeforeActivate event ........................................................................................................ 131
BeforeClose event ............................................................................................................. 132
BeforeModalDialog event................................................................................................ 133
BeforeOpen event ............................................................................................................. 136
Caption property .............................................................................................................. 137
Changed property............................................................................................................. 138
Close method..................................................................................................................... 139
EventMode property ....................................................................................................... 140
Height property ............................................................................................................... 142
Hide method ..................................................................................................................... 143
IsLoaded property ............................................................................................................ 144
Left property ..................................................................................................................... 145
Move method ................................................................................................................... 146
Name property ................................................................................................................. 147
Open method..................................................................................................................... 148
PullFocus method............................................................................................................. 150
Required property ............................................................................................................ 152
Show method .................................................................................................................... 153
Top property ..................................................................................................................... 154
Visible property ................................................................................................................ 155
Width property ................................................................................................................. 157
Chapter 9: Field Object ............................................................................................. 159
AfterGotFocus event ........................................................................................................ 160
AfterLostFocus event ....................................................................................................... 161
AfterUserChanged event................................................................................................. 162
BeforeGotFocus event ...................................................................................................... 163
BeforeLostFocus event ..................................................................................................... 164
BeforeUserChanged event............................................................................................... 165
Caption property .............................................................................................................. 167
Changed event .................................................................................................................. 168
Empty property................................................................................................................. 170
Enabled property.............................................................................................................. 171
Focus method.................................................................................................................... 172
FocusSeg method.............................................................................................................. 173
C O N T E N T S
iv V B A D E V E L O P E R S G U I D E
Height property ............................................................................................................... 175
Left property .................................................................................................................... 176
Locked property............................................................................................................... 177
Move method ................................................................................................................... 178
Name property ................................................................................................................ 179
Object property................................................................................................................. 180
Parent property................................................................................................................. 182
Required property............................................................................................................ 183
TabStop property.............................................................................................................. 184
Top property .................................................................................................................... 185
Value property.................................................................................................................. 186
ValueSeg property............................................................................................................ 189
Visible property ............................................................................................................... 190
Width property ................................................................................................................ 191
Chapter 10: Grid Object............................................................................................ 193
AfterLineChange event ................................................................................................... 194
AfterLineGotFocus event ................................................................................................ 195
AfterLineLostFocus event............................................................................................... 196
BeforeLineChange event ................................................................................................. 197
BeforeLineGotFocus event ............................................................................................. 198
BeforeLineLostFocus event............................................................................................. 199
BeforeLinePopulate event............................................................................................... 200
Changed property............................................................................................................ 201
EventMode property ...................................................................................................... 202
Hide method .................................................................................................................... 203
Left property .................................................................................................................... 204
Move method ................................................................................................................... 205
Name property ................................................................................................................ 207
Showmethod ................................................................................................................... 208
Top property .................................................................................................................... 209
Visible property................................................................................................................ 210
Chapter 11: Report Object...................................................................................... 211
BeforeAF event ................................................................................................................. 212
BeforeAHevent ................................................................................................................ 213
BeforeBody event ............................................................................................................. 214
BeforePF event.................................................................................................................. 215
BeforePHevent................................................................................................................. 216
BeforeRF event.................................................................................................................. 217
BeforeRHevent................................................................................................................. 218
Cancel method.................................................................................................................. 219
End event........................................................................................................................... 220
EventMode property ...................................................................................................... 221
Legend property............................................................................................................... 222
Name property ................................................................................................................ 223
Start event.......................................................................................................................... 224
V B A D E V E L O P E R S G U I D E v
C O N T E N T S
Chapter 12: VBAGlobal Object........................................................................... 225
DUOSObjectCombineID method................................................................................... 226
DUOSObjectExtractID method....................................................................................... 228
DUOSObjectsGet method................................................................................................ 230
Chapter 13: DUOSObjects Collection......................................................... 233
Exists property .................................................................................................................. 234
Itemproperty..................................................................................................................... 235
Name property.................................................................................................................. 236
Remove method................................................................................................................ 237
SortByExisting property .................................................................................................. 238
Chapter 14: DUOSObject Object...................................................................... 241
ID property ........................................................................................................................ 242
Properties property........................................................................................................... 243
Chapter 15: DUOSProperties Collection................................................... 245
Count property.................................................................................................................. 246
Exists property .................................................................................................................. 247
Itemproperty..................................................................................................................... 248
Remove method................................................................................................................ 250
Chapter 16: DUOSProperty Object ................................................................ 251
Name property.................................................................................................................. 252
Value property................................................................................................................... 253
Appendix.................................................................................................................................. 256
Appendix A: VBA Errors........................................................................................... 257
Handling VBA errors ............................................................................................................... 257
VBA error reference.................................................................................................................. 258
Glossary..................................................................................................................................... 265
Index............................................................................................................................................... 269
vi V B A D E V E L O P E R S G U I D E
I
N
T
R
O
D
U
C
T
I
O
N
2 V B A D E V E L O P E R S G U I D E
Introduction
Microsoft Visual Basic