VB A Developers Guide
VB A Developers Guide
Copyright
Trademarks
Microsoft, Excel, Microsoft Dynamics, Outlook, Visual Basic, Windows, and Windows Vista 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 800456-0025 (in the U.S. or Canada) or +1-701-281-6500.
Publication date
April 2007
Contents
Introduction ................................................................................................................................. 2
Whats in this manual .................................................................................................................. 2
Prerequisites .................................................................................................................................. 2
Product support ............................................................................................................................ 3
Symbols and conventions............................................................................................................ 3
Whats next .................................................................................................................................... 4
VBA
DEVELOPERS
GUIDE
C O N T E N T S
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
ii
V B A
D E V E L O P E R S
G U I D E
C O N T E N T S
VBA
DEVELOPERS
GUIDE
iii
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
C O N T E N T S
VBA
DEVELOPERS
GUIDE
vi
V B A
D E V E L O P E R S
G U I D E
INTRODUCTION
Introduction
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,
fields and reports. In addition, you can attach VBA code to fields you create
using the Modifier.
Prerequisites
Keep in mind that VBA is a powerful programming language, and a basic
knowledge of VBA programming concepts is required. If you havent
worked with VBA before, we strongly recommend you review one of the
many books available that discuss programming with VBA.
The remainder of the manual assumes that you are already familiar with
VBAs programming concepts and features, as well as Microsoft Dynamics
GP. It explains how to use your existing VBA knowledge to work with the
VBA capabilities available with the accounting system.
V B A
D E V E L O P E R S
G U I D E
IN TRO DUCT IO N
Product support
Technical support for VBA can be accessed by the following methods:
Description
Convention
Description
Chapter 1, VBA
Overview
set 'l_Item' to 1.
RUNTIME.EXE
TAB
or ALT+M
VBA
DEVELOPERS
GUIDE
I N T R O D U C T I O N
Whats next
Before 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 the
components necessary to support the VBA environment.
2. Register the Modifier.
To activate the VBA environment, you must register the Modifier. The
registration keys to register the Modifier are supplied with the
accounting system. Once youve registered the Modifier, you can access
the Visual Basic environment.
3. Review Chapter 1, VBA Overview.
This chapter explains the basics of how the accounting system
integrates with the Visual Basic environment. Once youve reviewed
the information in this chapter, you can use the remainder of the
manual to learn specific ways you can use VBA with the accounting
system.
V B A
D E V E L O P E R S
G U I D E
V B A
D E V E L O P E R S
Chapter 1, VBA Overview, explains the basics of the VBA environment and how it integrates with Microsoft Dynamics GP. It also
explains the components of Microsoft Dynamics GP youll use when
creating projects in VBA.
Chapter 6, Storing Additional Data, explains how to store userdefined data using the Dynamic User Object Store (DUOS).
G U I D E
Chapter 1:
VBA Overview
Before you start using VBA, its important that youre familiar with the
VBA components specific to Microsoft Dynamics GP. The following
sections explain each of these in detail:
To open the Visual Basic Editor, point to Customize on the Tools submenu,
and then choose Visual Basic Editor.
To create or edit VBA code, you must have appropriate user privileges. Typically,
this means being part of the Administrators group or the Power Users group on
Windows XP. On Windows Vista, it means launching Microsoft Dynamics GP
with Administrative privileges.
VBA
DEVELOPERS
GUIDE
PA RT
U S I N G
V B A
The Visual Basic Editor is similar for each host application, so if youve
used VBA with Microsoft Excel or Word, the Visual Basic Editor in
Microsoft Dynamics GP will be familiar.
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
V B A
O V E R V I E W
You can view a project using the Visual Basic Project Explorer:
Windows, reports and fields are not automatically part of the project. When
you begin working with VBA, youll selectively add to your project the
window, field and report objects you want to work with. Once added to
your project, you can reference these objects in VBA. In addition, the Visual
Basic Editor lets you add VBA user forms, user-defined procedures and
user-defined class modules to your VBA project.
The VBA Editor lets you develop and maintain a single project at a time. To
work with several different projects, store each project file in a separate
location. When you need to work on a project, copy it to the same location
of the runtime engine, then rename the file name.VBA, where name is the
name of the dictionary the project is based on.
After youve completed a VBA project file, youll distribute it to users. This
file contains your VBA code, the objects youve referenced in your VBA
code, and any VBA user forms you choose to use.
VBA
DEVELOPERS
GUIDE
PA RT
U S I N G
V B A
Objects
Applications expose their functionality to VBA through a set of
programmable objects. These objects include windows, reports, grids and
Dynamic User Object Store (DUOS) objects. The relationship each object has
to another object is expressed in a hierarchical object model, shown in the
following illustration:
Window
Window fields
Report
Report fields
Grid
Window fields
UserInfo
DUOSObjects
DUOSObject
DUOSProperties
DUOSproperty
Object
Collection Object
10
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
V B A
O V E R V I E W
Windows
Most of the VBA programming youll complete for windows will involve
the following objects.
Object
Description
Window
Window field
Grids
Grids are VBAs definition of a scrolling window. When working with
grids, youll use the following objects:
Object
Description
Grid
Window field
Reports
When working with reports, youll use the following objects:
Object
Description
Report
Represents a report.
Report field
User information
When implementing a VBA integration, you may need to retrieve
information about the user currently logged into Microsoft Dynamics GP.
The UserInfo object provides access to this information. Refer to Chapter 17,
UserInfo Object, for more information about retrieving user information.
VBA
DEVELOPERS
GUIDE
11
PA RT
U S I N G
V B A
Description
DUOSObjects collection
DUOSObject object
DUOSProperties collection
DUOSProperty object
Programming model
Each object in the object model has defined methods and properties you can
use in VBA code to manipulate the behavior of the object. Methods and
properties for objects are declared using standard VBA object.method and
object.property syntax. Most objects also have specific events that specify
when associated VBA code executes for the object.
Methods
Methods are actions you can perform for a given object. Methods include
opening and closing a window or moving a field in a window. For example,
the field object uses the Focus method to move the focus to a different field
in the window:
'Move the focus to the salesperson field
SalespersonID.Focus
Properties
Properties are characteristics you can retrieve or set for a given object.
Properties include the title of a window, or the value of a field. For example,
you can use the Caption property to change the name of a window or field:
'Change the prompt for a field
CustomerMaintenance.CustomerID.Caption = "Patient ID"
'Change the title of a window
CustomerMaintenance.Caption = "Patient Maintenance"
12
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
V B A
O V E R V I E W
Events
Youll write the majority of your VBA code within individual event
procedures. Each event procedure executes VBA code at certain times for a
specific object, such as when the user changes the value of a field, clicks a
button, prints a report, or opens a window. You can see these predefined
event procedures in the VBA Code window.
Object list.
Event procedures specify
when VBA code runs. The
event procedures listed
here are specific to
window objects.
The primary reason to use VBA with the Modifier is to apply programming
logic to new fields you add to a window using the Modifier. By using VBA
with fields added using the Modifier, you can:
Add new data entry fields that store additional data in the Dynamic
User Object Store (DUOS). Refer to Chapter 6, Storing Additional
Data, for more information about using the DUOS.
VBA
DEVELOPERS
GUIDE
13
PA RT
U S I N G
V B A
Online help
After you install and register the Modifier, youll have access to online help
for the Visual Basic Editor, the VBA programming language, and for
objects, methods and properties in Microsoft Dynamics GP. Use either of
the following methods to display specific help topics:
Open the help for Microsoft Dynamics GP. A link to the VBA help can
be found there.
14
V B A
D E V E L O P E R S
G U I D E
Chapter 2:
Programming Windows
Programming windows using VBA involves adding a window to your
project, specifying the window events youll use to execute VBA code, and
using window methods and properties to customize window display.
Information about programming windows is divided into the following
sections:
Youll also likely want to customize a window using the windows fields
and scrolling windows (grids). Refer to Chapter 3, Programming Window
Fields, and Chapter 4, Programming Grids, for detailed information
about working with window fields and grids.
VBA
DEVELOPERS
GUIDE
15
PA RT
U S I N G
V B A
Switch to the Visual Basic Editor and display the Project Explorer. It should
look similar to the following:
The Project Explorer displays
the window objects youve
added to the project. Objects
for third-party applications
appear in a separate project.
16
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
You can continue to switch between the Visual Basic Editor and the main
application to add windows as needed throughout your projects
development. When viewed in the accounting system, each window youve
added to your project will appear with a period (.) at the end of the
windows title. This provides technical support and VBA developers with a
visual cue that the window is part of the VBA project.
The following section, Using window events, explains each type of window
event you can use to execute VBA code. Windows also contain window
fields that you can reference and manipulate through VBA. Refer to
Chapter 3, Programming Window Fields, for more information about
using window fields.
VBA
DEVELOPERS
GUIDE
17
PA RT
U S I N G
V B A
The section titled Using window properties and methods explains the methods
and properties available to procedures in your VBA project.
18
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
If you use VBA with a window youve modified using the Modifier, you
must set the EventMode property to emModified if you want events to
occur for the modified window. To change the EventMode property for the
window object, use the Visual Basic Properties window.
If you delete a modified window from your forms dictionary (or delete the forms
dictionary altogether), all VBA references to new fields you add to the modified
window will be invalid. If you re-create the modified window, then re-add the new
fields using the Modifier, youll need to re-add those same fields to your VBA
project and re-create any VBA customizations that reference the new fields.
BeforeOpen event
The BeforeOpen event occurs before the Microsoft Dynamics GP code runs
for the window open event. Its useful when you want to set default field
values in the window, while still allowing any Microsoft Dynamics GP
application code to override your defaults. In the following example, the
event procedure sets the Checkbook ID field when the Invoice Batch Entry
window opens. If this window displays an existing record when opened
(such as when opened from a zoom field), Microsoft Dynamics GP
application code overrides this value with the value stored with the record:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
'Set the checkbook ID
CheckbookID = "PETTY CASH"
End Sub
This event also includes the OpenVisible parameter. When set to False, this
specifies that the window should open invisibly.
VBA
DEVELOPERS
GUIDE
19
PA RT
U S I N G
V B A
AfterOpen event
The AfterOpen event occurs after the Microsoft Dynamics GP code runs for
the window open event. Its useful for overriding any default values that
were set for window fields. In the following example, the event procedure
marks both check box controls when the Sales Territory Maintenance
window opens. Since Microsoft Dynamics GP application code sets defaults
for these fields when the window opens, using the AfterOpen event
overrides the defaults:
Private Sub Window_AfterOpen()
'Set both check boxes when the window opens
MaintainHistory = 1
MaintainHistory1 = 1
End Sub
BeforeClose event
The BeforeClose event occurs before Microsoft Dynamics GP application
code runs for the window close event. The primary use for this event is to
cancel the window close if the contents in the window dont meet certain
criteria. The following event procedure for the Invoice Entry window
checks whether the user entered a comment ID for the transaction, and
displays a message dialog. If the user clicks Yes, the procedure cancels the
close using the AbortClose parameter, and the user can enter a comment ID:
Private Sub Window_BeforeClose(AbortClose As Boolean)
Dim Response As Integer
If CommentID.Empty = True Then
'Display a message box
Response = MsgBox("Do you want to enter a Comment?", vbYesNo)
If Response = vbYes Then
'They want to enter a comment
AbortClose = True
CommentID.Focus
End If
End If
End Sub
20
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
AfterClose event
The AfterClose event occurs after the Microsoft Dynamics GP application
code runs for the window close event. The AfterClose event is a generalpurpose event you can use to perform any clean-up tasks, such as closing
other windows. For example, the following event procedure runs when the
Customer Maintenance window closes. It closes the Customers And
Prospects lookup window if its open (its IsLoaded property is True):
Private Sub Window_AfterClose()
If CustomersAndProspects.IsLoaded = True Then
CustomersAndProspects.Close
End If
End Sub
VBA
DEVELOPERS
GUIDE
21
PA RT
U S I N G
V B A
PromptString
Control1String
Control2String
Control3String
You apply a modal dialog event to a window in the same manner as other
window events. However, instead of occurring when the window opens,
closes or activates, the modal dialog event occurs for the window whenever
a modal dialog opens.
BeforeModalDialog event
The VBA BeforeModalDialog event occurs when Microsoft Dynamics GP
opens a modal dialog, but before its displayed. Since the dialog is open, but
not visible, this event allows you to dismiss the dialog by programmatically
answering it for the user. In the following example, if a user enters a nonexistent shipping method in the Customer Maintenance window, Microsoft
Dynamics GP displays an ask dialog asking whether the user wants to add
the shipping method. Normally the user must dismiss the dialog manually,
by clicking Add or Cancel. Instead, the event procedure automatically
answers this dialog and removes a step in the data entry process:
Private Sub Window_BeforeModalDialog(ByVal DlgType As Boolean, _
PromptString As String, Control1String As String, Control2String _
As String, Control3String As String, Answer As Long)
If PromptString = "Do you want add this Shipping Method?" Then
'Click the first button, the Add button
Answer = dcButton1
End If
End Sub
22
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
The PromptString parameter is the message text, which you can use to filter
which modal dialog you want to respond to. The Answer parameter uses
the constants dcButton1, dcButton2 and dcButton3. When indicated, these
click the first, second or third button in the dialog.
The BeforeModalDialog event is also useful for altering the contents of the
dialog before its displayed, including the modal dialogs message text and
button text. The following event procedure changes the message and button
text:
Private Sub Window_BeforeModalDialog(ByVal DlgType As Boolean, _
PromptString As String, Control1String As String, Control2String _
As String, Control3String As String, Answer As Long)
If PromptString = "Do you want to add this shipping method?" Then
'Change the message text
PromptString = "Create this shipping method?"
'Change "Add" button to "Create"
Control1String = "Create"
End If
End Sub
AfterModalDialog event
The VBA AfterModalDialog event occurs when Microsoft Dynamics GP
opens a modal dialog, but after the user dismisses it. This event allows you
to ascertain how the user responded to the dialog and perform any
additional tasks based on that response.
Refer to Chapter 6,
Storing Additional
Data, for more
information about
using the Dynamic
User Object Store
(DUOS).
The primary use for the AfterModalDialog event is to keep data in the
accounting system synchronized with data youve stored using the
Dynamic User Object Store (DUOS). For instance, if youve created a DUOS
object that stores Internet address information for a customer, youll likely
want to save it when the user saves the corresponding customer record.
In the following example, the user attempts to close a window without
saving a customer record. In this case, Microsoft Dynamics GP will display
a modal dialog asking if the user wants to save the record. If the user clicks
the modal dialogs Save button, the event procedure saves the
corresponding DUOS object:
VBA
DEVELOPERS
GUIDE
23
PA RT
U S I N G
V B A
24
V B A
D E V E L O P E R S
The following table explains the available window methods and properties.
The remainder of this section explains some of the more common methods
and properties youll use when working with windows, as well as
additional ways you can use windows.
Property/Method
Description
Activate method
Caption property
Close method
EventMode property
Height property
Hide method
IsLoaded property
Left property
Move method
G U I D E
C H A P T E R
Property/Method
P R O G R A M M I N G
W I N D O W S
Description
Name property
Open method
Opens a window.
PullFocus method
Show method
Top property
Visible property
Required property
VBA
DEVELOPERS
GUIDE
25
PA RT
U S I N G
V B A
Use the Modifiers Form Definition window to find out which windows are
part of a form.
26
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
Activating a window
The VBA Activate method activates a visible, open window, making it the
frontmost window, or expands it if its minimized. The Activate method
also causes the windows activate event to occur. In the following example,
the event procedure activates the Invoice Entry window after closing the
Invoice Batch Entry window:
Private Sub Window_AfterClose()
If InvoiceEntry.Visible = True Then
InvoiceEntry.Activate
End If
End Sub
Hiding windows
The VBA Hide method hides a window youve opened, making it invisible.
The Visible property, when set to False, also makes a window invisible.
While invisible, the window is open (its IsLoaded property is True) and
data in the window is accessible.
Making a window invisible is useful if you need to reference data contained
in the window without necessarily displaying the window to the user. For
example, when the user enters a transaction amount in the Receivables
Transaction Entry window, the following event procedure compares the
amount with the maximum batch total in an invisible Receivables Batch
Entry window:
Private Sub SalesAmount_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
If BatchID.Empty = False Then
'The user selected a batch
'Click the expansion button to open the Batch Entry window
ExpansionButtons = 1
'Make the window invisible
ReceivablesBatchEntry.Visible = False
'Compare the batch total to the trx amount entered
If CCur(SalesAmount) >CCur(ReceivablesBatchEntry _
.BatchTotal) Then
MsgBox "Amount exceeds batch limit. Select another batch."
'Clear the batch ID field and move the focus there
BatchID.Empty = True
BatchID.Focus
End If
'Close the window
ReceivablesBatchEntry.Close
End If
End Sub
VBA
DEVELOPERS
GUIDE
27
PA RT
U S I N G
V B A
28
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W S
Renaming a window
The Name property allows you to change VBAs internal reference to a
window object. Note that this is not the same as the Caption property,
which allows you to change the windows title. If you change the windows
Name property using the Visual Basic Properties window, the name will
change in your project. You should then recompile your project to replace
any references to that window with the new name. Youll find it necessary
to rename a window if its name conflicts with other object names in your
project, such as reserved words in VBA.
VBA
DEVELOPERS
GUIDE
29
30
V B A
D E V E L O P E R S
G U I D E
Chapter 3:
VBA
DEVELOPERS
GUIDE
31
PA RT
U S I N G
V B A
Using the mouse, click on each data entry field, push button or list field
youll use in your project. Be sure to click on the field itself, and not the
fields prompt. When youve finished adding fields, point to Customize on
the Tools menu, and choose Add Fields to Visual Basic to deactivate field
selection mode.
Field selection mode also deactivates when you switch to the Visual Basic Editor.
Window fields youve added to a project wont appear in the Visual Basic
Project Explorer like a window, report or grid object. Instead, they will
appear in the Visual Basic Code window for a window object.
32
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
The following illustration shows window field objects for the Receivables
Customer Maintenance window object:
At this point, you can write VBA code for the window field object using a
window field event, or you can reference the window field from other VBA
procedures in your project.
VBA
DEVELOPERS
GUIDE
33
PA RT
U S I N G
V B A
34
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Window field events execute VBA procedures when a user moves to,
changes, or moves out of a window field, or a field youve added using the
Modifier. To view field events, choose a field object in the Code windows
Object list; all the window field events will appear in the Procedure list.
Select the window field
object in the Object list.
Event syntax appears
automatically when you
choose an event.
Window field events
appear in the
Procedure list.
When you choose an event, VBA automatically adds the event procedure
syntax to the Code window. You can then write the event procedure using
that event syntax.
There are four basic kinds of field events youll work with in VBA: got focus,
user changed, changed and lost focus. Each event occurs relative to when the
user moves the focus into a field (a got focus event), when the value of a field
changes (a user changed or changed event) or when the user moves the focus
out of a field (a lost focus event).
These events are useful when you want to respond to data the user enters in
a field by performing other operations in the window. For example, the
following AfterUserChanged event procedure runs when the user changes
information in the State field:
Private Sub State_AfterUserChanged()
If State = "NJ" Then
'Default the salesperson and territory
SalespersonID = "MARILYN H."
TerritoryID = "TERRITORY 4"
End If
End Sub
VBA
DEVELOPERS
GUIDE
35
PA RT
U S I N G
V B A
Field events also respond to actions performed by the user, such as clicking
a button. In the following example, a new button (OpenMSWord) added to
a window using the Modifier uses the AfterUserChanged event to open
Microsoft Word:
Private Sub OpenMSWord_AfterUserChanged()
Dim App As Word.Application
Set App = CreateObject("Word.Application")
App.Visible = True
End Sub
Each window field event you define occurs either before or after the
Microsoft Dynamics GP code for the field event runs. Therefore, field
events have names like BeforeUserChanged to indicate that the event
runs when the user changed the contents, but before the Microsoft Dynamics
GP application code runs.
36
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
If Microsoft Dynamics GP runs application code during the got focus event,
it typically checks the value of the field thats gaining focus, and performs
calculations or sets other field values based on that value. However,
Microsoft Dynamics GP uses this event infrequently to do such operations.
BeforeGotFocus event
The BeforeGotFocus event occurs before the Microsoft Dynamics GP code
for the got focus event. Use this event to set or evaluate the contents of the
field gaining focus, and cancel any further got focus events from running
(the Microsoft Dynamics GP got focus event and the VBA AfterGotFocus
event). When set to True, the CancelLogic parameter will cancel the fields
other got focus events. In this example, the BeforeGotFocus event
procedure cancels the AfterGotFocus event for the Batch ID field (shown in
the description of the AfterGotFocus event below):
Private Sub BatchID_BeforeGotFocus(CancelLogic As Boolean)
If DocumentType = 7 Then
'The document type is a return. Dont use a batch
BatchID.Empty = True
'Cancel the AfterGotFocus event, which opens the lookup
CancelLogic = True
MsgBox "Post returns individually, not in a batch."
DocumentDate.Focus
End If
End Sub
AfterGotFocus
The AfterGotFocus event occurs after the Microsoft Dynamics GP code runs
for the got focus event. Use this event to set or evaluate the contents of a
field gaining focus. In the following example, the AfterGotFocus event for
the Batch ID field checks whether the field is empty when the user moves to
it. If it is, the event procedure opens the batch lookup window:
Private Sub BatchID_AfterGotFocus()
If BatchID.Empty = True Then
'The field is empty. Click the lookup button
LookupButton3 = 1
End If
End Sub
VBA
DEVELOPERS
GUIDE
37
PA RT
U S I N G
V B A
User enters information in the Name field and presses the TAB key:
1. VBA BeforeUserChanged event occurs for the Name field.
2. Microsoft Dynamics GP user changed event occurs for the Name field.
3. VBA AfterUserChanged event occurs for the Name field.
Its common for Microsoft Dynamics GP to use the user changed event to
verify the contents of a field when the field changes; however, this isnt
done for all fields.
In fields that toggle, such as push buttons and visual switches, the user
changed event occurs when the user clicks the field. Microsoft Dynamics
GP always executes application code during the user changed event for
these fields.
38
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
In list fields, such as button drop lists and list boxes, user changed events
occur when the user selects an item from the list, or presses the up arrow or
down arrow keys to move to a different list item.
User selects an item in the list:
1. VBA BeforeUserChanged event occurs
for the list.
2. Microsoft Dynamics GP user changed event
occurs for the list.
3. VBA AfterUserChanged event occurs for
the list.
BeforeUserChanged
The BeforeUserChanged event occurs before the Microsoft Dynamics GP
code runs for the user changed event. Use this event to evaluate the value of
the field and bypass, or cancel, any Microsoft Dynamics GP processing that
occurs for the same field.
Use caution when canceling Microsoft Dynamics GP processing for a fields user
changed event. Canceling the user changed event processing inhibits the
accounting systems ability to verify the contents of a field.
In the following example, the BeforeUserChanged event procedure runs
for the Invoice Entry windows Trade Discount field. Using the CancelLogic
parameter, it cancels processing for the Trade Discount field if the user
enters an amount greater than 4% of the invoice subtotal. It also uses the
KeepFocus parameter to place the focus in the same field, allowing the user
to enter a lower amount:
Private Sub TradeDiscount_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
If TradeDiscount > Subtotal * 0.04 Then
'The trade discount is greater than 4% of the subtotal
'Cancel the invoice calculation
CancelLogic = True
TradeDiscount.Value = Subtotal * 0.04
KeepFocus = True
MsgBox "You cannot enter a discount greater than 4% of " + _
"the subtotal."
End If
End Sub
VBA
DEVELOPERS
GUIDE
39
PA RT
U S I N G
V B A
AfterUserChanged
The AfterUserChanged event occurs after the Microsoft Dynamics GP code
for the user changed event runs. Use this event to evaluate information the
user entered in a field. The following example uses the AfterUserChanged
event to check the value of the Customer ID field in the Invoice Entry
window, then disable the Trade Discount field:
Private Sub CustomerID_AfterUserChanged()
If CustomerID = "ADVANCED0002" Then
'Don't offer a trade discount
TradeDiscount.Enable = False
End If
End Sub
Changed event
The VBA Changed field event always occurs for a field when its contents
change. This includes:
The most common situation to use the Changed event is when you want to
execute VBA code for window fields that Microsoft Dynamics GP updates.
This occurs most often when the accounting system retrieves a record from
a table, then displays the records contents in window fields. The
AfterUserChanged and BeforeUserChanged events wont occur for these
fields, since the application, not the user, changes the contents of the field.
Exercise caution when using the Changed event. In many cases, Microsoft
Dynamics GP may cause the Changed event to occur numerous times for the same
field even though the value of the field may not visibly change. This will execute the
associated VBA event procedure each time the event occurs.
For example, as the user browses through records in the Receivables
Transaction Entry window, Microsoft Dynamics GP sets window field
values for each record. The following Changed event procedure runs for
the Document Date field. Each time the user moves to a new record, it
checks the value of the document date, and displays a message if the
document is older than 30 days:
40
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Microsoft Dynamics GP rarely uses the lost focus event. When it is used, it
typically locks control fields (fields that control the display of a record).
BeforeLostFocus
The BeforeLostFocus event occurs before the Microsoft Dynamics GP code
for the lost focus event. You can use the BeforeLostFocus event to cancel
any subsequent lost focus events for the field. When set to True, the
CancelLogic parameter cancels the Microsoft Dynamics GP lost focus and
VBA AfterLostFocus events.
VBA
DEVELOPERS
GUIDE
41
PA RT
U S I N G
V B A
When set to True, the KeepFocus parameter allows you keep the focus in the
current field.
AfterLostFocus
The AfterLostFocus event occurs after the Microsoft Dynamics GP code
runs for the lost focus event. You can use the AfterLostFocus event to
evaluate the value of the field losing focus, and perform any additional
operations in the window. The following AfterLostFocus event procedure
checks whether the Payment Terms field is empty. If it is, the procedure
displays a VBA dialog that asks the if the user wants to enter a payment
term. If the user clicks Yes, the procedure opens the Payment Terms Lookup
window:
Private Sub PaymentTerms_AfterLostFocus()
Dim Response As Integer
If PaymentTerms.Empty = True Then
'Set a default payment term
Response = MsgBox("Do you want to enter a payment term?", _
vbYesNo)
If Response = vbYes Then
LookupButtons = 1
End If
End If
End Sub
42
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
The following table explains the available methods and properties for
window fields. The remainder of this section explains some of the more
common methods and properties youll use when working with window
fields.
Property/Method
Description
Caption property
Empty property
Enabled property
Focus method
FocusSeg method
Height property
Left property
Locked property
Move method
Name property
Object property
Parent property
Required property
TabStop property
Top property
Value property
ValueSeg method
Visible property
Width property
VBA
DEVELOPERS
GUIDE
43
PA RT
U S I N G
V B A
In this case, the user can browse information in the window, but not create
new account records or delete existing ones.
You can use VBA to set the value of a field youve locked or disabled using
VBA. However, you cannot set the value of a field locked or disabled by
Microsoft Dynamics GP, nor can you unlock or enable these fields.
Microsoft Dynamics GP disables fields when they dont apply in a given
situation, and lock fields to preserve the integrity of accounting data (such
as document totals).
44
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
When working with windows, you cannot move the focus using the
windows BeforeOpen event. Since the window isnt open yet, theres no
place for the focus to be placed. You can, however, move the focus using the
windows AfterOpen event.
You can still return or set the values of fields you make invisible with VBA.
However, you cannot set the value of fields hidden by Microsoft Dynamics
GP, nor can you show these fields.
VBA
DEVELOPERS
GUIDE
45
PA RT
U S I N G
V B A
Renaming fields
The Name property allows you to change the name you use in VBA code to
reference the field. Note that this is not the same as the Caption property,
which allows you to change the fields caption. You can change a fields
name using the Visual Basic Properties window, and the name will change
in your project. You should then recompile your project to replace any
references to that field with the new name.
Youll find it necessary to rename fields if the fields name conflicts with a
reserved word in VBA. For example, the Date field has the same name as a
reserved word in VBA. You may also want to rename fields to make code
more readable.
46
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
You return and set window field values using the Value property. If your
code specifies the field name, but omits the Value property, VBA assumes
youre returning or setting the value of the field. The following example
explicitly uses the Value property:
BatchID.Value = "DEBITMEMOS"
The same code can also omit the Value property and have the same effect:
BatchID = "DEBITMEMOS"
The majority of the examples in this manual use the abbreviated form of
this syntax. You can choose to use or ignore the Value property in your
own project.
VBA
DEVELOPERS
GUIDE
47
PA RT
U S I N G
V B A
You can also use the ValueSeg property to set individual segments in a
composite. However, theres little difference in using the Value and
ValueSeg properties to do this. In the following example, the ValueSeg
property is used to set the first and second segments in the Account field.
Private Sub Account_AfterGotFocus()
CashAccount.ValueSeg(1) = "100"
'Set the second segment
CashAccount.ValueSeg(2) = "1100"
'Move the focus to the third segment
CashAccount.FocusSeg(3)
End Sub
The following event procedure has the same effect, but uses the Value
property to set the composites value:
Private Sub Account_AfterGotFocus()
CashAccount.Value = "100-1100"
CashAccount.FocusSeg (3)
End Sub
48
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
VBA returns all field values as strings. For instance, VBA returns the values
of a currency field as $30.75, a date field as 5/1/00, and an integer field
as 100.
To avoid this problem, you must convert these values using VBAs numeric
conversion functions prior to performing the comparison. In the following
example, VBAs CInt() function converts the ItemQuantity1 and
ItemQuantity2 fields, resulting in a correct comparison:
If CInt(Quantity1) > CInt(Quantity2) Then
'Quantity1 (70) is now less than Quantity2 (100)
VBA
DEVELOPERS
GUIDE
49
PA RT
U S I N G
V B A
The following table shows the VBA functions available for converting
string values to a specific data type:
Function
Description
CInt()
CDate()
CCur()
CLng()
You can use the Value property to set a fields value for any field in a
Microsoft Dynamics GP window, providing the window that contains the
field is open (the windows IsLoaded property is True). If the window is
open but invisible, you can set field values from that window. If youve
disabled, locked or hidden the field using VBA, you can still set the fields
value. If the accounting system disables, locks or hides the field, you cannot
set the fields value.
Each type of field accepts specific values from VBA. For setting data entry
fields, such as string, date and currency fields, you typically use a string
value from VBA:
'Set a the Batch ID string field
BatchID = "DEBITMEMOS"
'Set the Document Date field
DocumentDate = "02/07/97"
'Set the Discount Amount currency field
DiscountAmount = "120.95"
Other fields, such as list fields, check boxes, push buttons and radio
buttons, accept numeric values:
'Set the Document Type drop-down list to item 2
DocumentType = 2
'Mark the Hold check box
Hold = 1
'Push the Save button
Save = 1
'Select the first option in the Posting Type radio button group
PostingType = 0
50
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
VBA
DEVELOPERS
GUIDE
51
PA RT
U S I N G
V B A
When the user moves out of the Shipping Method field, the Microsoft
Dynamics GP code for the user changed event checks whether the fields
data is valid. In this case, it will make sure NEW is an existing shipping
method. Since this is a new shipping method, a dialog will appear asking
whether the user wants to add it.
You cannot set the fields value using events that follow the Microsoft Dynamics
GP user changed event (AfterUserChanged, AfterLostFocus or
BeforeLostFocus events). Microsoft Dynamics GP doesnt have the opportunity
to verify values set in these events, and a VBA error will occur. You can use these
events to read the value of the field.
52
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
Refer to Appendix A,
VBA Errors, for an
explanation of each
VBA error you may
encounter.
P R O G R A M M I N G
W I N D O W
F I E L D S
The VBA error occurs because the accounting system attempts to place the
focus in the field and restore the fields previous value. Since the current
field does not have focus, Microsoft Dynamics GP cannot place the focus
and the VBA error results.
This type of error will commonly occur when you set an add-on-the-fly
field to a new value from outside the field. The following AfterOpen
event procedure for the Receivables Transaction Entry window sets the
value of an add-on-the-fly field (Shipping Method):
Private Sub ReceivablesTransactionEntry_AfterOpen()
'Set the Shipping Method field to a value that doesn't exist.
ShippingMethod = "NEW"
End Sub
In this case, the accounting system will display a dialog asking whether you
want to add the new shipping method. When you dismiss the dialog, VBA
generates an error, since the system cannot place the focus in the Shipping
Method field.
There are two ways to avoid this type of error:
Whenever possible, set a fields value from inside the field, after its
gained focus, using the fields AfterGotFocus or BeforeGotFocus field
event. If your event procedure sets an invalid value, the accounting system will still display a dialog, but VBA wont generate the error:
Private Sub ShippingMethod_AfterGotFocus()
'Set the Shipping Method field to a value that doesn't exist.
ShippingMethod = "NEW"
End Sub
If you set the value outside the field, before the field has gained
focus, use the Focus method with the setvalue parameter in your event
procedure. The Focus method moves the focus to the field, then sets its
value to the setvalue:
Private Sub CustomerID_AfterUserChanged()
'Move the focus to the field, then set the value
ShippingMethod.Focus("NEW")
End Sub
VBA
DEVELOPERS
GUIDE
53
PA RT
U S I N G
V B A
Field list
The fields described are listed below. Detailed explanations of each follow.
54
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
A button drop list allows a user to select one item from the list. The
following illustration shows a button drop list.
Button drop list
List items
Events
VBA usage
Comments
Example
The following event procedure chooses the first item in the Write Letters
button drop list in the Customer Maintenance window.
Private Sub PrintCollections_Click()
'Print a collections letter
CustomerMaintenance.coWriteLettersBDL = 1
End Sub
VBA
DEVELOPERS
GUIDE
55
PA RT
U S I N G
V B A
Check box
Description
A check box allows the user to mark or unmark an item. The following
illustration shows a check box.
Check box caption
Events
All VBA field events function for a focusable check box field.
VBA usage
VBA uses numeric values when referencing a check box field. If 1, the check
box is marked; if 0, the check box is unmarked.
Comments
You can change a check box caption using the Caption property. For two or
more check boxes linked to a single caption (such as the Calendar Year and
Fiscal Year check boxes linked to the Maintain History caption), you can
change only the check box group caption, not the captions for individual
check boxes.
Example
The following event procedure runs when the Sales Territory Maintenance
window opens. It marks the first check box (Calendar Year) in the Maintain
History group, and unmarks the second check box (Fiscal Year):
Private Sub Window_AfterOpen()
'Mark this check box when the window opens
MaintainHistory = 1
'Unmark this check box when the window opens
MaintainHistory1 = 0
End Sub
56
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Combo box
Description
A combo box allows the user to enter a text item or choose one from the
combo box list. The following illustration shows a combo box.
Caption
Events
VBA usage
VBA uses string values for each item in a combo box. When you set the
value of a combo box, VBA sets the value to the combo box field. If the
value doesnt exist in the item list, VBA wont add it to the list. However,
Microsoft Dynamics GP application code typically asks the user if they
want to save a new item in the combo box field when the user dismisses the
window.
Example
The following event procedure checks the value of the Budget Year combo
box field in the Budget Maintenance window, then enables or disables the
Display radio group:
Private Sub BudgetYear_AfterUserChanged()
'Check the Budget Year combo box
If BudgetYear = "2004" Then
'Disable the Display radio group
Display.Enabled = False
Else
Display.Enabled = True
End If
End Sub
VBA
DEVELOPERS
GUIDE
57
PA RT
U S I N G
V B A
Composite
Description
Events
VBA usage
You can return the value of a composite using either the Value property or
the ValueSeg property. If you use the Value property, VBA returns a
formatted string value. If you use the ValueSeg property, VBA returns the
unformatted value of the segment you specify.
You can also set the value of a composite using either the Value property or
the ValueSeg property. Use the Value property to set the value of the entire
composite, including any formatting characters, such as dashes. Use the
ValueSeg property to set the value of individual segments of the composite,
without including any formatting. Use the FocusSeg method to move the
focus between segments of a composite field.
Examples
The following example uses the Value property to set the Cash Account
composite field to an existing account number:
Private Sub CheckbookID_AfterUserChanged()
If CheckbookID = "FIRST NATIONAL" And CashAccount.Enabled _
= True Then
CashAccount = "100-5100-00"
CashAccount.Enabled = False
Else
CashAccount.Enabled = True
End If
End Sub
58
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
The following event procedure uses the ValueSeg property to set the
default value of the first segment in the Cash Account composite field. It
then uses the FocusSeg method to place the focus on the second segment in
the composite:
Private Sub CashAccount_AfterGotFocus()
CashAccount.ValueSeg(1) = "100"
CashAccount.FocusSeg(2)
End Sub
VBA
DEVELOPERS
GUIDE
59
PA RT
U S I N G
V B A
Currency
A currency field displays a value as a currency amount. The following
illustration shows a currency field.
Description
Caption
Currency field
Events
VBA usage
VBA uses a formatted string value when referencing a currency field. The
value can have a maximum of 14 characters to the left of a decimal
separator and 5 to the right.
When you set a currency value, specify the location of the decimal
separator; the accounting system automatically provides all other
formatting. When you return a currency value, VBA returns the formatted
string value that appears in the window, including the currency symbol,
thousands separator and the decimal separator.
Example
The following VBA code defaults the value of a currency field to a fixed
amount in the Checkbook Maintenance window:
Private Sub CheckbookID_AfterUserChanged()
If NextCheckNumber = 1 Then
'This is a new checkbook.
'Set the max check amount to $2,000.00
Amount = "2000.00"
End If
End Sub
60
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Date
Description
Events
VBA usage
VBA uses a formatted string value when referencing a date field. When you
set a date value, the text value must match the operating system settings for
date and time, such as 12/31/96 (using MM/DD/YY format) or
31-12-96 (using DD-MM-YY format).
Examples
In the following example, VBA code sets the value of a date field to a fixed
string value:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
PostingDate = "07/28/97"
End Sub
In the following example, VBA code combines a string with a date field to
construct a new batch ID in the Invoice Entry window:
Private Sub DocumentType_AfterGotFocus()
If DocumentType = 2 Then
'The user selected returns
'Place the focus in the Batch ID field and set the value
BatchID.Focus("RET-" + Str(UserInfoGet.UserDate))
'Constructs "RET-07/28/97" as the batch ID
End If
End Sub
VBA
DEVELOPERS
GUIDE
61
PA RT
U S I N G
V B A
Drop-down list
Description
Events
VBA usage
Comments
Example
DocumentType = 7
End Sub
62
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Integer
Description
Events
VBA usage
VBA uses a string value when referencing an integer field. If the integer
field includes a format (such as a percent field), VBA returns the formatted
string value, including the decimal separator and percent sign (such as
3.15%). To set the value of a formatted integer field, only include the
decimal separator (3.15). The accounting system adds any other
formatting characteristics.
Examples
In the following example, VBA code sets the Transaction Total integer field
to 50 when the user enters a new batch in the Sales Batch Entry window:
Private Sub BatchID_AfterUserChanged()
If Origin = 0 Then
'No batch origin specified. This is a new batch.
TransactionTotal = "50"
End If
End Sub
This example sets an integer field (Percent) thats formatted with two
decimal places. It calculates a new commission percent based on
commissioned sales:
Private Sub CommissionedSales_BeforeUserChanged(KeepFocus _
As Boolean, CancelLogic As Boolean)
If CCur(CommissionedSales) + CCur(NonCommissionedSales) > _
200000 Then
Percent = "4.50"
Else
Percent = "3.00"
End If
End Sub
VBA
DEVELOPERS
GUIDE
63
PA RT
U S I N G
V B A
List box
Description
A list box displays up to 32,767 items in a list, one of which the user can
select. The following illustration shows a list box.
Caption
Events
VBA usage
VBA uses a numeric value (1 to n) when referencing list box fields. In most
cases, the value corresponds to the position of an item in the list. You cannot
reference the name of the item in the list, nor can you rearrange, remove or
add items to a list box using VBA.
Comments
Example
The following example sets the default selection in the Currencies list box
when the Multicurrency Access Setup window opens:
Private Sub Window_AfterOpen()
Currencies = 8
'Selects Z-US$
End Sub
64
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
A multi-select list box displays up to 32 items in a list, from which the user
can choose multiple items. The following illustration shows a multi-select
list box.
Caption
Events
VBA usage
VBA uses a 32-bit numeric value when referencing the items selected in a
multi-select list box. The numeric value takes into account both the number
of items selected and their position in the list. The following table shows the
position of an item in a multi-select list box, the items corresponding
numeric value, and the calculation that derives the value:
List item
Numeric value
Calculated as...
20
21
22
23
31
1,073,741,824
230
The value of the list is the sum of the selected items numeric values. If you
select items 1, 3 and 4, the value of the multi-select list box is 13 (total = 1 +
4 + 8). An easier way to determine the value of the list is to select multiple
items, then view the fields Value property in the Visual Basic Properties
window.
VBA
DEVELOPERS
GUIDE
65
PA RT
U S I N G
V B A
Examples
To select a single item in a multi-select list box, set the multi-select list boxs
value to the items numeric value (noted in the previous table). The
following example selects list item 4 by setting the list boxs value to 8:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
'Select Payroll in the list
IncludeinLookup = 8
End Sub
To select multiple items in a multi-select list box, add the list items numeric
values together. The following example selects list items 1, 3 and 4 by
setting the field to the sum of the items integer values (1 + 4 + 8 = 13):
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
'Select Sales, Purchasing and Payroll
IncludeinLookup = 13
End Sub
66
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Push button
Description
Events
VBA usage
VBA uses numeric values when referencing push buttons. The value
indicates the state of the push button. The up, or normal state of the
button is 0; the down, or pushed state is 1. Setting the buttons value to 1
in effect pushes the button, and performs the same operation as if the
user clicked the button.
Comments
You can change a text push buttons caption using the Caption property.
Examples
The following example displays a lookup window when the user moves to
the Batch ID field and the field is empty. To display the lookup window, the
procedure sets the lookup button field to 1:
Private Sub BatchID_AfterGotFocus()
If BatchID.Empty = True Then
'The field is empty. Press the lookup button.
LookupButton3 = 1
End If
End Sub
VBA
DEVELOPERS
GUIDE
67
PA RT
U S I N G
V B A
Radio button
Description
A radio button field appears within a radio button group. You can select
only one button in the group. The following illustration shows a radio
button group.
Radio button group
caption
Radio button group
Events
VBA usage
VBA uses numeric values when referencing a radio button group. The
numeric value indicates the selected radio button in the group and
corresponds to the order each radio button appears in the tab sequence,
starting with 0 for the first field in the sequence. In the Typical Balance
radio button group pictured above, the Debit field is 0 and the Credit field
is 1.
Comments
You can change the radio button groups caption using the
Caption property. You cannot change the captions for individual radio
buttons.
Example
The following example selects the Code radio button control in the Method
Of Entry radio button group when the window opens:
Private Sub Window_BeforeOpen
'Set the Code radio button
MethodofEntry = 1
End Sub
68
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
String
Description
A string field allows you to enter and view up to 255 text characters. The
following illustration shows a string field.
Caption
String field
Events
VBA usage
VBA uses a string value when referencing string fields. If you set the value
of a string field that uses a format (such as a phone number field), include
all formatting characters, including parentheses, static text, dashes and
spaces. When you return the value of a formatted string value, VBA returns
the formatted string value.
Example
The following example sets the value of the Batch ID string field when the
user chooses a document type from the Document Type drop-down list in
the Receivables Transaction Entry window:
Private Sub DocumentType_AfterUserChanged()
Select Case DocumentType
'Move the focus to the Batch ID field and set the value
Case 1
BatchID.Focus("DAILYSLS")
Case 7
BatchID.Focus("DAILYRET")
Case Else
BatchID.Focus("DAILYMISC")
End Select
End Sub
In the following example, the procedure sets the value of the Phone 1 field
using a formatted string:
Private Sub CustomerID_Changed()
If CustomerID = "AARONFIT0001" Then
Phone1 = "(701) 555-7890
Ext. 1234"
End If
End Sub
VBA
DEVELOPERS
GUIDE
69
PA RT
U S I N G
V B A
Text
Description
Text field
Events
VBA usage
VBA uses a string value when referencing a text field. The string value
cannot exceed 32,000 characters.
Comments
Example
The following example adds a note to an Invoice record when the customer
purchases over $2,000. The message added to the text field in the Note
window explains that the customer received a 4% trade discount:
Private Sub TradeDiscount_AfterGotFocus()
If Subtotal >= 2000 And TradeDiscount = 0 Then
'Click the note button to open the Note window
NoteAbsentButtonWindowArea = 2
'Add a message to the text field
Note.TextField = "Customer " + Name1 + " purchased " + _
"over $2,000. The trade discount for Customer " + Name1 + _
" was calculated and applied at 4%."
'Click the Attach button to save the note
Note.Attach = 2
'Set the trade discount to 4% of the subtotal
InvoiceEntry.TradeDiscount = Subtotal * 0.04
End If
End Sub
70
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
W I N D O W
F I E L D S
Visual switch
Description
A visual switch displays a series of text or picture items. Clicking the field
displays the next item in the series. The following illustration shows a
visual switch field.
Events
VBA usage
VBA uses numeric values when referencing visual switch fields. The
numeric value corresponds to the currently-displayed item in the series,
starting with 1 and incremented by 1. For a visual switch with two pictures
in the series, the first picture in the list has a value of 1 and the second has a
value of 2.
Example
The following example expands the scrolling window in the Invoice Entry
window when the window initially opens:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
ScrollingWindowExpandButton2 = 2
End Sub
VBA
DEVELOPERS
GUIDE
71
72
V B A
D E V E L O P E R S
G U I D E
Chapter 4:
Programming Grids
VBA refers to Microsoft Dynamics GP scrolling windows as grids.
Programming grids involves adding a grid to your project, determining
which grid events youll use to execute application code, and working with
the window fields that appear in the grid.
Information about grids is divided into the following sections:
VBA
DEVELOPERS
GUIDE
73
PA RT
U S I N G
V B A
74
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
G R I D S
Adding fields
Refer to Chapter 3,
Programming
Window Fields, for
more information
about working with
window fields.
Fields that appear within a grid use the same properties, methods and
events as fields that appear in a window. The only difference is that the
VBA references the grids fields within the context of the grid, and
references the windows fields within the context of the window.
VBA
DEVELOPERS
GUIDE
75
PA RT
U S I N G
V B A
Position the
selection pointer on
the field and click.
Using the mouse, click on the fields youll use in your project. You only
need to add fields from one line to your project. References you make to the
field in your VBA project will be for the line currently focused by the user,
so its not necessary to add the same field from multiple lines in the grid.
When youve finished adding fields, point to Customize on the Tools menu
and choose Add Fields to Visual Basic to deactivate field selection mode.
Field selection mode also deactivates when you switch to the Visual Basic Editor.
76
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
G R I D S
Types of grids
Three types of grids can be found in Microsoft Dynamics GP: browse-only,
editable and adds-allowed. Each type has unique characteristics.
Browse-only grids
Browse-only grids allow the user to view information but not change it.
Microsoft Dynamics GP uses browse-only grids in lookup windows.
These are captions for each
field in a grid line, and are
not part of the grid.
A browse-only grid
contains non-editable
lines.
VBA
DEVELOPERS
GUIDE
77
PA RT
U S I N G
V B A
Editable grids
Editable grids allow the user to change the contents of the selected line.
Microsoft Dynamics GP uses these types of grids to change multiple
options for one or more lines.
You can change the
information in an
editable grid.
Adds-allowed grids
Adds-allowed grids let the user add additional lines of information to the
grid. The grid stores the new information in a table. Microsoft Dynamics GP
commonly uses adds-allowed grids in transaction entry windows, where
the user can add multiple line items for a transaction.
78
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
G R I D S
There are four basic kinds of grid events youll work with in VBA: line got
focus, line changed, line lost focus and line populate events. Events occur when
the user displays a new line in a grid (a line populate event) moves the focus
into a grid line (a line got focus event), when the value of a line changes (a
line changed event), or when the user moves the focus out of a line (a line lost
focus event).
VBA
DEVELOPERS
GUIDE
79
PA RT
U S I N G
V B A
Microsoft Dynamics GP uses the line change event to save data in the line to
a table when the user leaves the line. An example of this is the Invoice Entry
window, where each grid line represents a separate transaction record in
the invoice. As the user moves to a new line, the line change event saves the
invoice line item to a table.
BeforeLineChange
The BeforeLineChange event occurs before Microsoft Dynamics GP code
runs for the line change event. Use this event when you want to check the
value of fields in a line, then cancel the Microsoft Dynamics GP line change
event if specified criteria arent met. The KeepFocus parameter cancels the
line change event that normally saves the contents of the line, and moves
the focus to the field that last had focus in the line.
In the following example, the BeforeLineChange event checks the value of
the Markdown Amount field in the Invoice Entry grid. If the user attempts
to enter a markdown amount greater than 20%, the KeepFocus parameter
stops the Microsoft Dynamics GP line change event and moves the focus
back to the current line:
Private Sub Grid_BeforeLineChange(KeepFocus As Boolean)
If CCur(MarkdownAmount) > CCur(UnitPrice) * 0.2 Then
'The markdown was greater than 20%
KeepFocus = True
MsgBox "You cannot enter a markdown greater than 20% " + _
"of the unit price."
End If
End Sub
AfterLineChange
The AfterLineChange event occurs after Microsoft Dynamics GP code runs
for the line change event. Use this event to perform other actions in the
window after the accounting system saves data in the line. For instance,
when the user enters line item information in the Invoice Entry grid, then
moves to the next line item, the following AfterLineChange event
procedure checks the Subtotal field. If the invoice subtotal is greater than
$1000, it assigns a specific batch ID to the transaction:
Private Sub Grid_AfterLineChange()
If CCur(InvoiceEntry.Subtotal) > 1000 Then
'Set the batch ID to an existing batch
InvoiceEntry.BatchID = "BIGSALES"
InvoiceEntry.BatchID.Locked = True
End If
End Sub
80
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R A M M I N G
G R I D S
The RejectLine parameter lets you selectively filter records from the grid
when its filled. Limit use of the RejectLine parameter, since it can have an
impact on application performance.
VBA
DEVELOPERS
GUIDE
81
PA RT
U S I N G
V B A
There are two properties available for the grid object: the Name property
and the EventMode property.
82
V B A
D E V E L O P E R S
G U I D E
Chapter 5:
Refer to the Report
Writer documentation
for additional
information about
customizing reports.
Programming Reports
Programming reports using VBA involves adding the report and report
fields to your project, choosing the report events youll use to execute VBA
code, and working with methods and properties to customize report
display. Information about programming reports is divided into the
following sections:
Although you created a modified report using Report Writer, this was only
necessary to access the reports layout and create the report object in VBA.
VBA
DEVELOPERS
GUIDE
83
PA RT
U S I N G
V B A
You can determine whether you want VBA code to run for either the
modified or the original version of the report using the reports EventMode
property. See the section titled Using modified or original reports on page 85
for more information about the EventMode property.
If the same field appears multiple times on a report, its important that you
select the field located in the report section from which you are going to
reference the field. For example, a report field may appear in the report
body and in the page footer. If you will be referencing the field from the
BeforePF event, be sure youre adding the field located in the page footer.
If the field is not a table field or a calculated field, the Add Fields To Visual
Basic menu item will appear disabled. To add several fields at once, hold
down the SHIFT key and select the fields, then choose Add Fields To Visual
Basic.
84
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
After youve added a report field to a project, you can reference it only from
within a report event procedure. Report fields, unlike window fields, have
no associated field events. Therefore, you cannot write VBA code
specifically for a report field.
There are two kinds of report events youll work with: start/end events and
band events. A Start event always occurs at the beginning of a report and an
End event always occurs at the end of a report. Band events occur when a
particular section of a report, or a band, prints.
VBA
DEVELOPERS
GUIDE
85
PA RT
U S I N G
V B A
Start/End events
Start/end events occur when the report starts and the report ends. The only
report data you have access to from start/end events are report legends,
which you can set or return in the Start event. To access report fields, you
must use band events.
Start event
For more information
about using VBA with
legends, refer to
Working with legend
fields on page 92.
The Start event occurs just before the report starts to print, before any data
actually prints. The primary use of the Start event is to set report legends
using the Legend property. Legends are fields whose data is persistent
throughout the report, and which must be passed to the report as it starts.
The following example sets the value of a legend field from the Start event:
Private Sub Report_Start()
RMCustomerReport.Legend(2) = "Aging Period Amount"
End Sub
You can also use the reports Start event to initialize any module-level
variables youll use for the report. The following examples use a modulelevel variable named Count to restrict a report to 10 customer records. The
Start event sets the counter to 0, then the BeforeAH event increments the
counter. After 10 records print, the BeforeAH event cancels the report using
the Cancel method.
'Declare a module-level variable
Private Count As Integer
--------------------------------------------------------------Private Sub Report_Start()
'Initialize the count
Count = 0
End Sub
--------------------------------------------------------------Private Sub Report_BeforeAH(ByVal Level As Integer, _
SuppressBand As Boolean)
'Increment the count
Count = Count + 1
If Count = 11 Then
RMCustomerReport.Cancel
End If
End Sub
86
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
End event
The End event occurs after a report prints. Use this event to perform any
clean-up activities for the report, launch other applications, or open and
close other windows. For example, the following End event procedure
launches Microsoft Outlook after the RM Customer Report prints:
Private Sub Report_End()
Dim Response As Integer
Dim RetVal As Variant
Response = MsgBox("Do you want to launch MS Outlook?", vbYesNo)
If Response = vbYes Then
RetVal = Shell("C:\Program Files\Microsoft Office\ + _
"Office\Outlook.exe", vbNormalFocus)
End If
End Sub
Band events
The report band
explained in this
section is the same as
the report section
thats explained in
Report Writer
documentation.
Page header
(BeforePH event)
Report header
(BeforeRH event)
Additional headers
(BeforeAH event)
Body
(BeforeBody event)
Additional footers
(BeforeAF event)
Report
Report footer
footer
(BeforeRF
(BeforeRF event)
event)
Page footer
(BeforePF event)
VBA
DEVELOPERS
GUIDE
87
PA RT
U S I N G
V B A
The primary use of a band event is to return or set the value of a field in a
corresponding band using the Value property. You can use a band event to
return a value for any report table field or calculated field. You can set a
value only for a user-defined calculated field youve added using the
Report Writer.
The BeforeAH event procedure can return the value of the Customer Name
table field, and set EMailAddress user-defined calculated field:
Private Sub Report_BeforeAF(By Val Level As Integer, SuppressBand _
As Boolean)
If CustomerName = "Aaron Fitz Electric" Then
'Set the user-defined calculated field
EMailAddress = "[email protected]"
End If
End Sub
88
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
Each band event includes a SuppressBand parameter. When set to True, the
SuppressBand parameter stops the current instance of the corresponding
band from printing. If a band prints multiple times in a report (such as the
report body), you can conditionally suppress a given instance of the band.
For example, the following BeforeBody procedure for the RM Salesperson
Report suppresses the current instance of the report body if the value of the
Commissioned Sales To Date field is less then $200,000:
Private Sub Report_BeforeBody(SuppressBand As Boolean)
If CCur(CommissionedSalesToDate) < 200000 Then
SuppressBand = True
End If
End Sub
If the report uses an accumulator field to calculate report totals or count the
number of bodies in a report, the accumulator field will still sum or count data from
fields in a suppressed band.
BeforePH event
The BeforePH event occurs before items in the page header print. Items in
the page header are placed at the top of every report page. Page number,
date and time fields are commonly placed in this section of a report.
BeforeRH event
The BeforeRH event occurs before items in the report header print. Items in
the report header appear only on the first page of a report. The title of the
report and introductory information are often included in this section. If a
page header is also included on the first page, the report header will appear
after the page header.
BeforeAH event
The BeforeAH event occurs before the reports additional header prints. A
report may have none, one or several additional headers, each indicated on
the report layout by H1, H2 and so on. Each prints when the data in the
field it is based on changes.
If a report uses multiple additional headers, use the BeforeAH events Level
parameter to specify an index corresponding to the number of the
additional header the event occurs for. In the following example, the
BeforeAH event procedure runs for the second additional header on a
report. The procedure also returns the value of the Checkbook ID field in
the second additional header:
VBA
DEVELOPERS
GUIDE
89
PA RT
U S I N G
V B A
If the report has only one additional header, the BeforeAH event occurs
only for that additional header, and you dont need to specify a value for
the Level parameter.
BeforeBody event
The BeforeBody event occurs before each instance of the reports body
prints. Microsoft Dynamics GP uses the report body for the bulk of a report,
which typically is made up of table fields. A report prints the body
repeatedly until all records in the report have printed.
BeforeRF event
The BeforeRF event occurs before the report footer prints. Items in the
report footer appear only on the last page of a report. Summary information
is often included the report footer. If a page footer is also included on the
last page, the report footer will print before the page footer.
BeforePF event
The BeforePF event occurs before the reports page footer prints. Items in
the page footer are placed at the bottom of every report page. The page
footer often includes administrative information, such as the name of the
person running the report.
BeforeAF event
The BeforeAF event occurs before the reports additional footer prints. A
report may have none, one or several additional footers, each indicated on
the report layout by F1, F2 and so on. Each prints when the data in the field
it is based on changes. Microsoft Dynamics GP uses the additional footer to
display summary data, such as a total of all records in the reports body.
If a report uses more than one additional footer, use the BeforeAF events
Level parameter to specify an index corresponding to the number of the
additional header you want the event to occur for. In the following
example, the BeforeAF event procedure runs for the second additional
footer that appears on the report:
90
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
If the report has only one additional footer, the BeforeAF event occurs only
for that additional footer, and you dont need to specify a value for the Level
parameter.
The following table explains the available report methods and properties.
The remainder of this section explains some of the more common methods
and properties youll use in when working with reports:
Property/Method
Description
Cancel method
EventMode property
Legend property
Name property
Canceling a report
You cancel a report using the Cancel method. The following example
cancels a report from the reports BeforeBody event:
Private Sub Report_BeforeBody(SuppressBand As Boolean)
If SalespersonID = "ERIN J." Then
RMSalespersonReport.Cancel
End If
End Sub
If you cancel a report from a reports band event, the report stops at that
band. If you cancel a report from a reports Start event, no data prints for
the report. In all cases, the reports End event will occur for a canceled
report. If the report is printed to the screen, the Cancel method closes the
Screen Output window automatically.
VBA
DEVELOPERS
GUIDE
91
PA RT
U S I N G
V B A
For example, to return the value of the Customer Class legend field, the
following Start event procedure includes a reference to the fields index:
Private Sub Report_Start()
If RMCustomerReport.Legend(5) = "AARONFIT0001 - AARONFIT0001" Then
'Cancel the report
RMCustomerReport.Cancel
End If
Table fields
Table fields are fields whose values derive directly from a Microsoft
Dynamics GP table. You can return only the value of table fields.
92
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
Calculated fields
Calculated fields are defined using table fields, constants and operators.
Microsoft Dynamics GP typically uses calculated fields to conditionally
print data on a report. You can only return the value of a Microsoft
Dynamics GP calculated field. You can set or return the value of a
calculated field you added to the report using Report Writer.
Accumulator fields
You can return the values of accumulator fields in a report. You can also
set the value of calculated fields you add to the report that function as
accumulator fields. An accumulator field is a table field or calculated field
that performs a specific function in the report, and whose field type is not
DATA. The field type for an accumulator field determines its function. For
instance, an accumulator field can count the number of occurrences of a
field (a COUNT field type), or calculate the sum total of each occurrence of
a numeric field (a SUM field type). Use the Report Writers Report Field
Options window to determine the field type for a selected field.
Field formats
With the exception of composite fields, VBA returns report field values
without any formatting. For instance, VBA returns the phone number (701)
555-0100 Ext. 1772 as 70155501001772. Likewise, VBA returns the currency
value $10.56 as 10.56000.
To format a report field value, use VBAs Format function. The Format
function allows you to define a format string for a specific field type (string
or numeric). The following example uses the Format function to format the
fax number string field:
MsgBox Fax
'Displays 70155501001772
'Use the format function to format the string
Format(Fax, "(@@@) @@@-@@@@
Ext. @@@@")
MsgBox Fax
'Displays (701) 555-0100 Ext. 1772
VBA
DEVELOPERS
GUIDE
93
PA RT
U S I N G
V B A
The following example uses the Visible property to hide the Total Sales
YTD field in the RM Customer Report if the Territory ID field is
TERRITORY 1:
Private Sub Report_BeforeAH(ByVal Level As Integer, SuppressBand As _
Boolean)
If SalesTerritory = "TERRITORY 1" Then
'Hide the YTD sales amount
TotalSalesYTD.Visible = False
Else
TotalSalesYTD.Visible = True
End If
End Sub
94
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
P R O G R AM M I N G
R E P O R T S
VBA
DEVELOPERS
GUIDE
95
PA RT
U S I N G
V B A
Ext. @@@@")
DynItem.BusinessFaxNumber = Format(Fax, _
"(@@@) @@@-@@@@
Ext. @@@@")
96
V B A
D E V E L O P E R S
G U I D E
Chapter 6:
The VBA object model uses two collections and two objects to define DUOS
data objects. The DUOSObjects collection contains one or more userdefinable collections you create to store related data objects, such as
customer, vendor or item collections. The DUOSObject object represents a
single data object within a collection, such as a customer object within a
customer collection. The following illustration shows the DUOS portion of
the VBA object model:
DUOSObjects
DUOSObject
DUOSProperties
DUOSproperty
Object
Collection Object
VBA
DEVELOPERS
GUIDE
97
PA RT
U S I N G
V B A
Object ID
Property name
Property value
Customers
ALTONMAN0001
URL Address
www.altonman.com
Contact E-Mail
Address
A collection named
"Customers"
ADVANCED0001
ITM001
ITM004
URL Address
www.advanced.com
Contact E-Mail
Address
Customer Type
RETAIL
Item Weight
2.45
Item Color
Blue
Item Weight
3.50
The Object ID is a unique value for a data object within its collection.
This ID cannot exceed 60 characters. You can specify the object ID using
the Item property from the DUOSObjects collection.
The Property name is a string that specifies the name of the property for
the object. The property name cannot exceed 30 characters. You can
define several property names for a data object. Each object in a collection may contain different property names. You can specify the property name using the Item property in the DUOSProperties collection.
A data object must have at least one property name to remain persistent in the
DUOS.
98
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
The Property value is a string that specifies the value of the property.
This value cannot exceed 132 characters. The DUOS stores all property
values as strings. You can specify a property value using the
Value property from the DUOSProperty object.
Collection
name
Object ID
Property
name
Property
value
Items
ITM000
Item Weight
3.5
Items
ITM000
Item Color
Red
Items
ITM001
Item Weight
2.45
Items
ITM001
Item Color
Blue
If two additional properties and property values are added to the ITM001
data object, the accounting system adds two records to this table:
Collection
name
Object ID
Property
name
Property
value
Items
ITM000
Item Weight
3.5
Items
ITM000
Item Color
Red
Items
ITM001
Item Weight
2.45
Items
ITM001
Item Color
Blue
Items
ITM001
Item Height
4.5
Items
ITM001
Item Width
2.75
Since Microsoft Dynamics GP stores DUOS data objects in a table, you can
use table maintenance windows to perform routine table maintenance.
VBA
DEVELOPERS
GUIDE
99
PA RT
U S I N G
V B A
100
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
VBA
DEVELOPERS
GUIDE
101
PA RT
U S I N G
V B A
You can also globally update DUOS data objects by looping through each
object in the collection. In this example, the For...Next statement in VBA
checks the Item Color property for each item in the ItemCollection. If the
value is Red, the collections Remove method deletes the object:
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Set ItemCollection = DUOSObjectsGet("Additional Item Info")
For Each ItemObject In ItemCollection
If ItemObject.Properties.Item("Item Color") = "Red" Then
'Delete the object
ItemCollection.Remove(ItemObject.ID)
End If
Next
Properties and methods youll use for the DUOS are members of three
objects and two collections in VBA. The following table lists each object, its
member properties and methods, and a brief description of each:
Object/
Collection
Property/ Method
Description
Global object
DUOSObjectCombineID
method
DUOSObjectExtractID
method
102
V B A
D E V E L O P E R S
G U I D E
Exists property
Item property
SortByExisting property
Type property
Remove method
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
Object/
Collection
Property/ Method
Description
DUOSObject
object
ID property
Properties property
Count property
Exists property
Item property
Remove method
Name property
Value property
DUOSProperties
collection
DUOSProperty
object
VBA
DEVELOPERS
GUIDE
103
PA RT
U S I N G
V B A
104
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
The user can click the Save button to save the changes, the Discard button
to ignore the changes, or the Cancel button to close the dialog and cancel
the save operation. In this situation, youll need to know when the user
clicks the Save button, and save any changes to the corresponding DUOS
data object. To do this, use a window AfterModalDialog event.
VBA
DEVELOPERS
GUIDE
105
PA RT
U S I N G
V B A
106
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
VBA
DEVELOPERS
GUIDE
107
PA RT
U S I N G
V B A
The user can either click Delete to delete the record, or click Cancel and
cancel the operation. Youll want to delete a DUOS object only if the user
clicks Delete in response to the dialog. Similar to saving DUOS objects, you
can accomplish this by using the AfterModalDialog event. The code that is
added to this event will then track whether the user selected the delete
button.
In some situations, theres one other condition youll need to address when
deleting a DUOS object. A second message dialog may appear if the
accounting system was unable to delete the record. For example, an
additional message will be displayed if a customer record has any
outstanding transactions corresponding to it.
The second message dialog needs to be handled differently than the delete
dialog. This is because theres no AfterModalDialog event available for the
secondary message. Instead, youll need to handle the message dialog as a
separate Microsoft Dynamics GP window and add it to your VBA project.
Once added, you use VBA code in the windows AfterOpen event to
ascertain whether the message prevented the record from being deleted.
The following series of examples show how to do this for DUOS data
objects stored with customer information.
108
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
VBA
DEVELOPERS
GUIDE
109
PA RT
U S I N G
V B A
In the following example, the event procedure runs when the user prints
the RM Customer Report. It updates two calculated string fields on the
report (DUOSCustomerWebAddress and DUOSCustomerEMailAddress)
with the data object in the customer collection. Since the new calculated
fields are in the reports additional header, this procedure uses the
BeforeAH event to set the field values before data in the additional header
prints.
110
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
S T O R I N G
A DD IT IO N A L
DA T A
Note that the RM Customer Report uses a field named Customer Number.
This is the same field as the Customer ID field referenced in the Customer
Maintenance window:
Private Sub Report_BeforeAH(ByVal Level As Integer, SuppressBand _
As Boolean)
Dim CustomerCollection As DUOSObjects
Dim CustomerObject As DUOSObject
'Return the customer collection
Set CustomerCollection = DUOSObjectsGet("CustomerCollection")
Set CustomerObject = CustomerCollection(CustomerNumber)
'Update the report fields
DUOSCustomerWebAddress = CustomerObject.Properties("URL Address")
DUOSCustomerEMailAddress = CustomerObject.Properties _
("Contact E-Mail Address")
End Sub
VBA
DEVELOPERS
GUIDE
111
112
V B A
D E V E L O P E R S
G U I D E
Chapter 7:
Distributing a Project
After youve developed and tested your project, you can distribute it to
individual workstations. This portion of the documentation describes
issues you need to be aware of when packaging and distributing VBA
projects. It contains the following sections:
Enabling VBA
References to external components
Distributing project files
Package files
Package file import/export issues
Enabling VBA
To use VBA, an installation of Microsoft Dynamics GP must have the
appropriate registration keys. These registration keys must provide access
to one of the following:
Refer only to components you need. Dont make references to components that arent being used in your project.
VBA
DEVELOPERS
GUIDE
113
PA RT
U S I N G
V B A
Watch for hidden references, such as those created when you add a
control to the Visual Basic toolbox.
Also, distributing an entire VBA project doesnt allow you to package any
modified forms or modified reports that may be part of your customization.
For all these reasons, we recommend that you use package files to distribute
your VBA customizations.
114
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
D I S T R I B U T I N G
P R O J E C T
Package files
Package files are special text files used to deliver customizations made with
the Modifier, VBA, and the Report Writer. A developer can create a package
file ontaining their customizations, move the package file to the destination
workstation, then import the customizations into the installation.
VBA
DEVELOPERS
GUIDE
115
PA RT
U S I N G
V B A
To select non-contiguous items in the list, hold down the CTRL key and click the
items.
Click Export. A file dialog will appear, allowing you to specify the
name of the package file. Be sure the file has the .package extension.
The results of the export operation will be displayed in the status area
at the bottom of the window.
Note that some global changes you make with the Modifier and Report Writer
cant be included in a package file. For instance, changes to picture resources or
global data types wont be included in package files.
116
V B A
D E V E L O P E R S
G U I D E
C H A P T E R
D I S T R I B U T I N G
P R O J E C T
VBA
DEVELOPERS
GUIDE
117
PA RT
U S I N G
V B A
118
V B A
D E V E L O P E R S
G U I D E
Chapter 10, Grid Object, describes the events and properties for grids
(scrolling windows).
Chapter 11, Report Object, describes the events, properties and methods for reports.
Chapter 12, VBAGlobal Object, describes the global methods available for the Dynamic User Object Store (DUOS).
Chapter 17, UserInfo Object, describes the properties and method for
retrieving information about the current user.
The syntax descriptions and programming style used in this part are the
same as those used in VBAs documentation.
120
V B A
D E V E L O P E R S
G U I D E
Chapter 8:
Window Object
Your project uses the window object to perform several tasks related to
windows. The events, methods and properties that apply to the window
object are listed below. A detailed explanation of each follows.
Activate method
AfterActivate event
AfterClose event
AfterModalDialog event
AfterOpen event
BeforeActivate event
BeforeClose event
BeforeModalDialog event
BeforeOpen event
Caption property
Changed property
Close method
EventMode property
Height property
Hide method
IsLoaded property
Left property
Move method
Name property
Open method
PullFocus method
Required property
Show method
Top property
Visible property
Width property
VBA
DEVELOPERS
GUIDE
121
C T I V A T E
M E T H O D
Activate method
Description
Syntax
window.Activate
Parameters
Comments
Examples
Related items
Events
The window objects BeforeActivate event and AfterActivate event.
122
V B A
D E V E L O P E R S
G U I D E
F T E R
C T I V A T E
E V E N T
AfterActivate event
Description
Syntax
window_AfterActivate()
Parameters
Comments
Examples
Related items
VBA
DEVELOPERS
GUIDE
123
F T E R
L O S E
E V E N T
AfterClose event
Description
The AfterClose event occurs when the window closes. It occurs after the
Microsoft Dynamics GP window close event.
Syntax
window_AfterClose()
Parameters
Comments
Microsoft Dynamics GP typically uses the window close event to check for
any unsaved changes, or whether the user entered all required fields in the
window, and display the appropriate dialog.
Examples
In this example, the AfterClose event closes a lookup window after the
Customer Maintenance window closes:
Private Sub CustomerMaintenance_AfterClose()
If CustomersAndProspects.IsLoaded = True Then
CustomersAndProspects.Close
End If
End Sub
Related items
124
V B A
D E V E L O P E R S
G U I D E
F T E R
O D A L
I A L O G
E V E N T
AfterModalDialog event
Description
Syntax
Parameters
Description
dtModalAskDialog
dtModalGetStringDialog
Description
dcButton1
dcButton2
dcButton3
dcCancel
dcOK
VBA
DEVELOPERS
GUIDE
125
F T E R
O D A L
I A L O G
E V E N T
Comments
Ask dialogs
The dtModalAskDialog constant of the DlgType parameter specifies an ask
dialog. An ask dialog displays one or more buttons and message text. The
following illustration shows an ask dialog and the corresponding
parameters in the AfterModalDialog event:
PromptString
Control1String
Control2String
Control3String
126
V B A
D E V E L O P E R S
G U I D E
F T E R
O D A L
I A L O G
E V E N T
Getstring dialogs
The dtModalGetStringDialog constant of the DlgType parameter specifies a
getstring dialog. Getstring dialogs typically contain a message, a data entry
field, and OK and Cancel buttons:
PromptString
Control3String
Control1String
Control2String
This procedure runs when the accounting system displays an ask dialog
that prompts the user to save changes to a customer record in the Customer
Maintenance window. If the user clicks the Save button in the save dialog,
this procedure saves the corresponding DUOS object:
Private Sub Window_AfterModalDialog(ByVal DlgType As Long, _
PromptString As String, Control1String As String, _
Control2String As String, Control3String As String, Answer As Long)
Dim Customers As DUOSObjects
Dim Customer As DUOSObject
If PromptString = "Do you want to save changes to this " + _
"customer?" Then
'The user is trying to save the record using the save dialog
If Answer = dcButton1 Then'The user clicked Save
Set Customers = DUOSObjectsGet("Customer Info")
Set Customer = Customers(CustomerID)
Customer.Properties("URL Address") = URLAddress
Customer.Properties("Contact E-Mail Address") = _
ContactEMailAddress
End If
End If
End Sub
VBA
DEVELOPERS
GUIDE
127
F T E R
P E N
E V E N T
AfterOpen event
Description
The AfterOpen event occurs when a window opens. It occurs after the
Microsoft Dynamics GP window open event.
Syntax
window_AfterOpen()
Parameters
Comments
Microsoft Dynamics GP uses the window open event to set default field
values in the window, such as a default document date or a sort list
selection.
Since the AfterOpen event occurs after the Microsoft Dynamics GP open
event, use this event to override any default values that the accounting
system sets for window fields.
Examples
In this example, the AfterOpen event procedure for the Sales Territory
Maintenance window marks two check box controls when the window
opens, overriding the default values that the accounting system sets in its
open event:
Private Sub Window_AfterOpen()
'Set both check boxes when the window opens
MaintainHistory = 1
MaintainHistory1 = 1
End Sub
Related items
128
V B A
D E V E L O P E R S
G U I D E
E F O R E
C T I V A T E
E V E N T
BeforeActivate event
Description
Syntax
window_BeforeActivate()
Parameters
Comments
Examples
Related items
VBA
DEVELOPERS
GUIDE
129
E F O R E
L O S E
E V E N T
BeforeClose event
Description
The BeforeClose event occurs when the window closes. It occurs before the
Microsoft Dynamics GP window close event.
Syntax
window_BeforeClose(AbortClose As Boolean)
Parameters
Comments
Use this event is to cancel the window close if the contents in the window
dont meet certain criteria youve defined.
Examples
In the following example, the BeforeClose event procedure for the Invoice
Entry window checks whether the user entered a comment ID. If not, it
displays a message dialog using VBAs MsgBox() function. If the user clicks
Yes, the procedure cancels the close using the AbortClose parameter, and the
user can enter a comment ID:
Private Sub Window_BeforeClose(AbortClose As Boolean)
Dim Response As Integer
If CommentID.Empty = True Then
Response = MsgBox("Do you want to enter a Comment?", vbYesNo)
If Response = vbYes Then
AbortClose = True
CommentID.Focus
End If
End If
End Sub
Related items
130
V B A
D E V E L O P E R S
G U I D E
E F O R E
O D A L
I A L O G
E V E N T
BeforeModalDialog event
Description
Syntax
Parameters
Description
dtModalAskDialog
dtModalGetStringDialog
Description
dcButton1
dcButton2
dcButton3
dcCancel
dcOK
VBA
DEVELOPERS
GUIDE
131
E F O R E
O D A L
I A L O G
Comments
E V E N T
Ask dialogs
The dtModalAskDialog constant of the DlgType parameter specifies an ask
dialog. Ask dialogs display one or more buttons and message text. The
following illustration shows an ask dialog and the corresponding
parameters in the BeforeModalDialog event:
PromptString
Control1String
Control2String
Control3String
132
V B A
D E V E L O P E R S
G U I D E
E F O R E
O D A L
I A L O G
E V E N T
Getstring dialogs
The dtModalGetStringDialog constant of the DlgType parameter specifies a
getstring dialog. Getstring dialogs typically contain a message, a data entry
field, and OK and Cancel buttons:
PromptString
Control3String
Control1String
Control2String
In
this
example,
the
BeforeModalDialog
event
procedure
programmatically answers a dialog for the user. The dialog opens when the
user enters a nonexistent shipping method. Before the accounting system
can display this dialog, the procedure automatically clicks the Add
button, allowing the user to add the new shipping method:
Private Sub Window_BeforeModalDialog(ByVal DlgType As Long, _
PromptString As String, Control1String As String, Control2String _
As String, Control3String As String, Answer As Long)
If PromptString = "Do you want add this Shipping Method?" Then
'Click the first button, the Add button
Answer = dcButton1
End If
End Sub
VBA
DEVELOPERS
GUIDE
133
E F O R E
P E N
E V E N T
BeforeOpen event
Description
The BeforeOpen event occurs when a window opens. It occurs before the
Microsoft Dynamics GP window open event.
Syntax
window_BeforeOpen(OpenVisible As Boolean)
Parameters
Comments
Microsoft Dynamics GP typically uses the window open event to set default
field values in the window, such as a default document date or a sort list
selection. You can use this event to set default field values in the window,
while still allowing default values set by the accounting system to override
your defaults.
Examples
Related items
134
V B A
D E V E L O P E R S
G U I D E
A P T I O N
P R O P E R T Y
Caption property
Description
The Caption property specifies the windows title thats displayed to the
user.
Syntax
window.Caption [= string]
Parameters
Comments
Captions for data entry windows cannot exceed 80 characters. You cannot
change the caption for modal dialogs.
Windows modified using the Modifier include a period (.) at the beginning
of the windows caption. Windows that invoke VBA events include a
period at the end of the windows caption. These are visual indicators that
help technical support ascertain which windows youve modified. We
recommend you leave the period in the windows title.
Examples
The following example sets the title when the window opens:
Private Sub Window_BeforeOpen()
CustomerMaintenance.Caption = "Clients"
End Sub
Related items
VBA
DEVELOPERS
GUIDE
135
H A N G E D
P R O P E R T Y
Changed property
Description
Syntax
window.Changed [= boolean]
Parameters
Comments
A fields value changes when the user makes an entry in a field, or when
the fields value changes using VBA. In both of these instances, the
Changed property will return True for the current window.
The Changed property is useful for determining whether the contents of a
window changed, and performing an action based on those changes.
The Changed event for a field always runs whenever a new record is
displayed in a window (such as when the user is browsing records using
browse buttons). However, only the windows Changed property
ascertains whether the user actually modified the contents displayed in the
window.
Examples
The following example displays a message containing the date and time
when a customer record was changed. This information could also be
added to the DUOS or to another database (such as Microsoft Access) and
stored with the customer record.
Private Sub CustomerID_Changed()
If CustomerMaintenance.Changed Then
'The user made a change to the current record.
MsgBox "This user record was last changed on " & Date & _
" at " & Time & "."
End If
End Sub
Related items
136
V B A
D E V E L O P E R S
G U I D E
L O S E
M E T H O D
Close method
Description
Syntax
window.Close
Parameters
Comments
Examples
The following example uses the BeforeClose event to close the Customers
and Prospects lookup window when the Customer Maintenance window
closes:
Private Sub Window_BeforeClose()
If CustomersandProspects.IsLoaded = True Then
CustomersandProspects.Close
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
137
V E N T
O D E
P R O P E R T Y
EventMode property
Description
The EventMode property specifies whether VBA window events occur for
the original or modified version of the window.
Syntax
window.EventMode [= mode]
Parameters
Comments
Constant
Description
emOriginalOnly
emModifiedOnly
emNever
If you modify a window using the Modifier, VBA window events will occur
for the modified window only if you set the EventMode property to
emModified. To change the EventMode property for the window object,
use the Visual Basic Properties window.
If you modify a window containing a grid (such as a lookup window), you
must change the EventMode property to emModifiedOnly for both the
window and grid objects. Window and grid events can then occur for both
objects.
Windows modified using the Modifier include a period (.) at the beginning
of the windows caption. Windows that invoke VBA events include a
period at the end of the windows caption.
Examples
Typically, you set the windows EventMode property using the Visual Basic
Properties window. You can also set it through an event procedure, as
shown in the following example:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If CustomerMaintenance.Caption = ".CustomerMaintenance" Then
'This is a modified window. Shut off VBA events for this user
CustomerMaintenance.EventMode = emOriginalOnly
End If
End Sub
138
V B A
D E V E L O P E R S
G U I D E
Related items
V E N T
O D E
P R O P E R T Y
VBA
DEVELOPERS
GUIDE
139
E I G H T
P R O P E R T Y
Height property
Description
The Height property specifies the height of the window (in pixels).
Syntax
window.Height [= integer]
Parameters
Comments
The Height property specifies only the space within the windows client
area. The client area is the window less the windows title bar.
Examples
This example uses the Height property to set the height of the Invoice Entry
window:
Private Sub Window_BeforeOpen
'Set the height to 500 pixels
InvoiceEntry.Height = 500
End Sub
Related items
140
V B A
D E V E L O P E R S
G U I D E
I D E
M E T H O D
Hide method
Description
Syntax
window.Hide
Parameters
Comments
Use the Hide method to make any open window invisible. While invisible,
the window is open (its IsLoaded property is True) and data in the window
is still accessible. Use this method when you want to reference data
displayed in a window without making the window visible. You can also
make a window invisible using its Visible property, or by using the
OpenVisible parameter of the windows BeforeOpen event.
Examples
Related items
VBA
DEVELOPERS
GUIDE
141
O A D E D
P R O P E R T Y
IsLoaded property
Description
Syntax
window.IsLoaded[= boolean]
Parameters
Comments
Examples
Related items
142
V B A
D E V E L O P E R S
G U I D E
E F T
P R O P E R T Y
Left property
Description
The Left property specifies the horizontal position of the window (in
pixels).
Syntax
window.Left [= integer]
Parameters
Examples
In the following example, the event procedure uses the Left property to
open the Customer Maintenance window at a specified position:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
CustomerMaintenance.Left = 100
CustomerMaintenance.Top = 100
End Sub
Related items
VBA
DEVELOPERS
GUIDE
143
O V E
M E T H O D
Move method
Description
Syntax
Parameters
Comments
You can use named arguments for the Move method, or specify arguments
by position. If you use positional arguments, enter each in the order shown,
using commas and empty string values ("") to indicate the relative position
of arguments you dont specify.
Examples
The following example uses named arguments to move the left position of
and the top position of the window:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
InvoiceEntry.Move Left:=200, Top:=150
End Sub
Related items
144
V B A
D E V E L O P E R S
G U I D E
A M E
P R O P E R T Y
Name property
Description
The Name property specifies the internal name VBA uses to reference a
window.
Syntax
window.Name
Parameters
Comments
Examples
Related items
VBA
DEVELOPERS
GUIDE
145
P E N
M E T H O D
Open method
Description
Syntax
window.Open
Parameters
Comments
Use the Open method to open windows that initially appear empty,
with no existing record displayed.
If you use the Open method in your VBA code to open a window, but the
window cannot be opened, a VBA exception will be thrown. You can
handle this exception using the On Error statement in VBA.
Examples
146
V B A
D E V E L O P E R S
G U I D E
P E N
M E T H O D
The following procedure clicks the lookup button to display the Shipping
Methods lookup window:
Private Sub ShippingMethod_AfterGotFocus()
If ShippingMethod.Empty = True Then
'No shipping method specified. Click the lookup button
LookupButtons = 1
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
147
U L L
O C U S
M E T H O D
PullFocus method
Description
The PullFocus method removes the focus from a window and specifies
whether data for the currently-focused field is valid.
Syntax
window.PullFocus
Parameters
Return value
Comments
Description
True
The focus was pulled from the window. Microsoft Dynamics GP field
events (user changed and lost focus) verified that the focused field
contained valid data.
False
The focus was not pulled from the window. Microsoft Dynamics GP
field events determined that the focused field contained invalid data,
then displayed a message dialog.
148
V B A
D E V E L O P E R S
G U I D E
U L L
O C U S
M E T H O D
The following procedure runs when the user clicks a button in a VBA user
form. It saves the contents of the Receivables Transaction Entry window by
programmatically clicking the Save button. In this case, the save occurs
even though the user entered a non-existent shipping method in the
currently focused field in the window (Shipping Method). No warning
dialog appeared, and the partial shipping method wasnt saved:
Private Sub CommandButton1_Click()
ReceivablesTransactionEntry.Save = 1
ReceivablesTransactionEntry.Close
End Sub
Using the PullFocus method, the same example can conditionally save the
contents of the window only if data in the focused field is valid. In this case,
when the PullFocus method moves the focus out of the Receivables
Transaction Entry window, the Microsoft Dynamics GP user changed and
lost focus events verify the currently-focused field (Shipping Method). If
the field contains invalid data, the PullFocus method returns False, and the
save isnt performed:
Private Sub CommandButton1_Click()
If ReceivablesTransactionEntry.PullFocus = True Then
ReceivablesTransactionEntry.Save = 1
ReceivablesTransactionEntry.Close
End If
End Sub
VBA
DEVELOPERS
GUIDE
149
E Q U I R E D
P R O P E R T Y
Required property
Description
The Required property ascertains whether the user entered data in all
fields whose Required property is True.
Syntax
window.Required [= boolean]
Parameters
Comments
Required fields are those in which an entry is necessary to store the record
properly. You can make additional fields required using the field objects
Required property.
Use the window objects Required property when saving data objects to
the Dynamic User Object Store (DUOS). Since the accounting system wont
permit the user to save a record in a window without entering all required
fields, checking the Required property from VBA lets you save the DUOS
data object only when the accounting system permits the save.
Examples
In the following example, an event procedure for the save button saves
DUOS data objects in the Customer Maintenance window only if the user
entered all required fields (the Required property is True):
Private Sub Save_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
Dim CustomerCollection As DUOSObjects
Dim CustomerObject As DUOSObject
If CustomerMaintenance.Required = True Then
'The user entered all required fields. Create/get the collection
Set CustomerCollection = DUOSObjectsGet("CustomerCollection")
'Create the object, using the customer ID as the object ID
Set CustomerObject = CustomerCollection.Item(CustomerID)
'Set the properties in the collection
CustomerObject.Properties("URL Address") = URLAddress
CustomerObject.Properties("Contact E-Mail Address") _
= ContactEMailAddress
End If
End Sub
150
V B A
D E V E L O P E R S
G U I D E
H O W
M E T H O D
Show method
Description
Syntax
window.Show
Parameters
Comments
Examples
The following example shows a window thats open, but invisible. In this
case, the invisible window (Customer Maintenance Options) is from the
same form as the parent window (Customer Maintenance) from which this
event procedure is run:
Private Sub Country_AfterUserChanged()
If Country <> USA Then
MsgBox "Please choose a currency ID."
CustomerMaintenanceOptions.Show
CustomerMaintenanceOptions.CurrencyID.Focus
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
151
O P
P R O P E R T Y
Top property
Description
Syntax
window.Top [= integer]
Parameters
Examples
In the following example, the event procedure ascertains the position of the
Reminders window, then uses the Top property to align the top border of
the Customer Maintenance window with the top border of the Reminders
window:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If Reminders.Visible = True Then
'The Reminders window is open and visible
CustomerMaintenance.Top = Reminders.Top
End If
End Sub
Related items
152
V B A
D E V E L O P E R S
G U I D E
I S I B L E
P R O P E R T Y
Visible property
Description
Syntax
window.Visible [= boolean]
Parameters
Comments
You can make any window invisible, provided its open (its
IsLoaded property is True). While invisible, data in the window is still
accessible. Use this property when you want to reference data displayed in
a window without making the window visible.
You can also make a window invisible using the Hide method or the
OpenVisible parameter of the windows BeforeOpen event.
When you open a window, the accounting system implicitly opens all the
windows in the form invisibly, then displays the first window in the form
(the parent window). The child windows in the form remain invisible, but
loaded. You can use the Visible property to selectively display invisible
child windows without explicitly opening them.
Examples
VBA
DEVELOPERS
GUIDE
153
I S I B L E
P R O P E R T Y
Related items
154
V B A
D E V E L O P E R S
G U I D E
I D T H
P R O P E R T Y
Width property
Description
Syntax
window.Width [= integer]
Parameters
Examples
Related items
VBA
DEVELOPERS
GUIDE
155
156
V B A
D E V E L O P E R S
G U I D E
Chapter 9:
Field Object
Your project uses field objects to perform several tasks related to working
with fields in windows, grids and reports. The events, methods and
properties that apply to the field object are listed below. A detailed
explanation of each follows:
AfterGotFocus event
AfterLostFocus event
AfterUserChanged event
BeforeGotFocus event
BeforeLostFocus event
BeforeUserChanged event
Caption property
Changed event
Empty property
Enabled property
Focus method
FocusSeg method
Height property
Left property
Locked property
Move method
Name property
Object property
Parent property
Required property
TabStop property
Top property
Value property
ValueSeg property
Visible property
Width property
VBA
DEVELOPERS
GUIDE
157
F T E R
O T
O C U S
E V E N T
AfterGotFocus event
Description
The AfterGotFocus event occurs when the user moves the focus into a field,
using the TAB key or the mouse. It occurs after the Microsoft Dynamics GP
got focus event.
Syntax
field_AfterGotFocus()
Parameters
Comments
Examples
In the following example, the AfterGotFocus event for the Batch ID field
checks whether the field is empty when the user moves to it. If it is, the
event procedure opens the batch lookup window:
Private Sub BatchID_AfterGotFocus()
If BatchID.Empty = True Then
'The field is empty. Press the lookup button
LookupButton3 = 1
End If
End Sub
158
V B A
D E V E L O P E R S
G U I D E
F T E R
O S T
O C U S
E V E N T
AfterLostFocus event
Description
The AfterLostFocus event occurs when the user moves the focus out of a
field, using the TAB key or the mouse. It occurs after the Microsoft Dynamics
GP lost focus event.
Syntax
field_AfterLostFocus()
Parameters
Comments
Examples
VBA
DEVELOPERS
GUIDE
159
F T E R
S E R
H A N G E D
E V E N T
AfterUserChanged event
Description
The AfterUserChanged event occurs when the user changes the contents of
a field, then moves the focus out of the field, using the TAB key or the
mouse. In fields that toggle, such as push buttons and visual switches, this
event occurs when the user clicks the field. For list fields, this event occurs
when the user selects an item in the list. In all instances, the
AfterUserChanged event occurs after the Microsoft Dynamics GP user
changed event.
Syntax
field_AfterUserChanged()
Parameters
Comments
Use the AfterUserChanged event to evaluate the value in the field losing
focus. You cannot set the value of the field losing focus using the
AfterUserChanged event. This event occurs after the Microsoft Dynamics
GP user changed event, which is used to verify the contents of the field.
Examples
160
V B A
D E V E L O P E R S
G U I D E
E F O R E
O T
O C U S
E V E N T
BeforeGotFocus event
Description
The BeforeGotFocus event occurs when the user moves the focus to a field,
using the TAB key or the mouse. It occurs before the Microsoft Dynamics GP
got focus event.
Syntax
field_BeforeGotFocus(CancelLogic As Boolean)
field A window field object.
CancelLogic As Boolean If True, the event cancels the Microsoft Dynamics
GP got focus event, and the VBA AfterGotFocus event.
Comments
Use the BeforeGotFocus event to set or evaluate the contents of the field
gaining focus, and cancel any further got focus events for the field from
running (the Microsoft Dynamics GP got focus event and the VBA
AfterGotFocus event).
If Microsoft Dynamics GP uses its got focus event, it typically checks the
value of the field thats gaining focus, and performs calculations or sets
other field values based on that value. However, the accounting system
uses this event infrequently to do such operations.
Examples
In the following example, the procedure checks whether the document type
is a return. If so, this procedure cancels the VBA AfterGotFocus event
procedure, which automatically opens a lookup window for the Batch ID
field:
Private Sub BatchID_BeforeGotFocus(CancelLogic As Boolean)
If DocumentType = 7 Then
'The document type is a return. Dont use a batch
BatchID.Empty = True
'Cancel the VBA AfterGotFocus event, which opens a lookup
CancelLogic = True
MsgBox "Post returns individually, not in a batch."
DocumentDate.Focus
End If
End Sub
VBA
DEVELOPERS
GUIDE
161
E F O R E
O S T
O C U S
E V E N T
BeforeLostFocus event
Description
The BeforeLostFocus event occurs when the user moves the focus out of a
field, using the TAB key or the mouse. It occurs before the Microsoft
Dynamics GP lost focus event.
Syntax
Parameters
Comments
Use the BeforeLostFocus event to evaluate the value of the field losing
focus, and perform any additional operations in the window. You cannot
set the value of the field losing focus using the BeforeLostFocus event. This
event follows the Microsoft Dynamics GP user changed event, which is
used to verify the contents of the field losing focus.
The BeforeLostFocus event occurs immediately before the Microsoft
Dynamics GP lost focus event. The accounting system rarely uses its lost
focus event. When it does use this event, it typically locks control fields
(fields that control the display of a record).
Examples
162
V B A
D E V E L O P E R S
G U I D E
E F O R E
S E R
H A N G E D
E V E N T
BeforeUserChanged event
Description
The BeforeUserChanged event occurs when the user changes the contents
of a field, then moves the focus out of the field, using the TAB key or the
mouse. In fields that toggle, such as push buttons and visual switches, this
event occurs when the user clicks the field. For list fields, this event occurs
when the user selects an item in the list. In all instances, the
BeforeUserChanged event occurs before the Microsoft Dynamics GP user
changed event.
Syntax
Parameters
Comments
VBA
DEVELOPERS
GUIDE
163
E F O R E
S E R
H A N G E D
Examples
E V E N T
164
V B A
D E V E L O P E R S
G U I D E
A P T I O N
P R O P E R T Y
Caption property
Description
Syntax
field.Caption [= string]
Parameters
Comments
The following list explains the caption for each field type:
Field type
Caption
String, composite, currency, integer, The text thats linked to the field.
long integer, date, time, text, list
box, drop-down list, multi-select list,
combo box
Check box
Radio button
If you make a caption longer than the existing caption, keep in mind that
you may need to resize or rearrange fields to view the entire caption.
Examples
In the following example, the event procedure changes the caption for the
Customer ID field to Patient ID, then changes the windows caption:
Private Sub Window_BeforeOpen()
'Set the field caption
CustomerID.Caption = "Patient ID"
'Set the window caption
CustomerMaintenance.Caption = "Patient Maintenance"
End Sub
VBA
DEVELOPERS
GUIDE
165
H A N G E D
E V E N T
Changed event
Description
Syntax
field_Changed()
Parameters
Comments
When the user changes the field directly. This also activates the fields
BeforeUserChanged and AfterUserChanged events, as well as the
Microsoft Dynamics GP user changed event.
Use the Changed event to execute VBA code for window fields that
Microsoft Dynamics GP updates. This occurs most often when the
accounting system retrieves a record from a table, then displays the records
contents in the window. The AfterUserChanged and BeforeUserChanged
events wont occur for a field in this case, since the accounting system, not
the user, changes the contents of the field.
Exercise caution when using the Changed event. In many cases, Microsoft
Dynamics GP causes the Changed event to occur numerous times for the same
field even though the value of the field may not visibly change. This will execute the
associated VBA event procedure each time the event occurs.
166
V B A
D E V E L O P E R S
G U I D E
Examples
H A N G E D
E V E N T
In the following example, the Changed event procedure runs for the
Document Date field. As the user browses records in the Receivables
Transaction Entry window, the accounting system sets window field values
for each record browsed. This procedure checks the value of the Document
Date field, and displays a message if the document is older than 90 days:
Private Sub DocumentDate_Changed()
Dim DaysOld As Integer
If CDate(DocumentDate) < Date - 90 Then
'The document is at least 90 days old
DaysOld = Date - CDate(DocumentDate)
MsgBox "This document is " + Str(DaysOld) + " days old." + _
"Please post."
End If
End Sub
VBA
DEVELOPERS
GUIDE
167
M P T Y
P R O P E R T Y
Empty property
Description
Syntax
field.Empty [= boolean]
Parameters
Comments
To clear a fields value, set the fields Empty property to True. You cannot
clear a field that the accounting system locked or disabled, but you can
clear fields youve locked or disabled using VBA.
VBA considers numeric fields empty if they contain a value of 0. String
fields are empty if they contain nothing or only spaces. Date fields are
empty when the date is 00/00/00. Time fields are empty when the time is
12:00:00 AM.
Examples
168
V B A
D E V E L O P E R S
G U I D E
N A B L E D
P R O P E R T Y
Enabled property
Description
Syntax
field.Enabled [= boolean]
Parameters
Comments
A disabled field appears dimmed, along with its caption, the fields value,
and any related controls.
You can set the value of a field youve disabled using VBA. You cannot set
the value of a field disabled by the accounting system, nor can you enable
the field. For most windows, Microsoft Dynamics GP application code
disables and enables fields based on entries made by the user. You can
always return a disabled fields value.
Keep in mind that a disabled field is not the same as a locked field (a field
whose Locked property is True). If True, the Locked property makes the
field non-editable, but doesnt dim the fields value, prompt and related
controls.
Examples
Related items
VBA
DEVELOPERS
GUIDE
169
O C U S
M E T H O D
Focus method
Description
Syntax
field.Focus([setvalue])
Parameters
Comments
Use the Focus method to skip unnecessary fields in a window, or place the
focus in a specific field based upon a user entry. The Microsoft Dynamics
GP got focus event and the VBA BeforeGotFocus and AfterGotFocus
events occur when you move the focus to a field using the Focus method.
You cannot place the focus using a windows BeforeOpen or AfterOpen
event. By default, Microsoft Dynamics GP places the focus in the first field
in the tab sequence after these events occur.
Examples
In the following example, the Focus method redirects the focus to the
Shipping Method field when the user moves out of the Customer ID field:
Private Sub CustomerID_AfterUserChanged()
'Move the focus to the field.
ShippingMethod.Focus
End Sub
Using the setvalue parameter, the Focus method redirects the focus and sets
the value of the Shipping Method field:
Private Sub CustomerID_AfterUserChanged()
'Move the focus to the Shipping method field, then set the value
ShippingMethod.Focus("UPS BLUE")
End Sub
Related items
170
V B A
D E V E L O P E R S
G U I D E
O C U S
E G
M E T H O D
FocusSeg method
Description
Syntax
Parameters
Comments
Use the FocusSeg method to move the focus to a composite segment from
another field in the window, or from one segment to the next within the
same composite.
You can use the setvalue of the FocusSeg method to set the value of a
segment gaining focus. Based on whether youre setting the value from
inside or outside the field, there are two primary ways to set segment
values:
Examples
If you set the segments value from outside the composite field (from
another fields event procedure), use the setvalue parameter of the
FocusSeg method to set the segments value. In this case, you can set
only one segments value.
If you set the segments value from inside the composite field (from
the composite fields BeforeGotFocus, AfterGotFocus or BeforeUserChanged events), you can use the ValueSeg method to set values for
each segment of the composite. Use the FocusSeg method to move the
focus to a segment, but not set the segments value.
The following example sets an account number segment from outside the
Account field (using the Checkbook ID fields AfterUserChanged event).
The procedure moves the focus to the Account field, then sets the first
segment using the FocusSeg method:
Private Sub CheckbookID_AfterUserChanged()
'Move to the Account field and set the first segment
Account.FocusSeg (1), "100"
End Sub
VBA
DEVELOPERS
GUIDE
171
O C U S
E G
M E T H O D
The following example sets account segments from inside the Account
field. In this case, the Account field already has the focus. The
ValueSeg property sets the first two segment values. The FocusSeg
method then moves the focus to the third segment:
Private Sub CashAccount_AfterGotFocus()
If CheckbookID = "PAYROLL" Then
'Set default payroll account segments
CashAccount.ValueSeg(1) = "100"
CashAccount.ValueSeg(2) = "1500"
'Move the focus to the third segment
CashAccount.FocusSeg(3)
End If
End Sub
Related items
172
V B A
D E V E L O P E R S
G U I D E
E I G H T
P R O P E R T Y
Height property
Description
The Height property specifies the height of a window field (in pixels).
Syntax
field.Height [= integer]
Parameters
Comments
For data entry fields, the default height is 20 pixels. For push buttons, such
as Save and Delete, the default height is 24 pixels.
List box and multi-select lists require 20 pixels per item to display the item
properly. Changing the height of drop lists and combo boxes does not
change the height of the list in the undropped position. Instead, changing
the height of these lists determines the height of the list in the dropped
position.
Examples
In the following example, the event procedure changes the height of a list
box field in the Account Maintenance window so that it shows two items
rather than four:
Private Sub Window_BeforeOpen()
'Change the list to display only two items
IncludeinLookup.Height = 36
End Sub
Related items
VBA
DEVELOPERS
GUIDE
173
E F T
P R O P E R T Y
Left property
Description
The Left property specifies the horizontal position of a field (in pixels).
Syntax
field.Left [= integer]
Parameters
Comments
The Left property moves the field and the fields caption. It does not move
any buttons associated with the field, such as a lookup button. You must
move those fields separately.
Setting the Left property to 0 will align the field with the left edge of the
window. However, the fields caption will move off the window area.
Examples
In the following example, the event procedure runs when the Account
Maintenance window opens. It first hides the Budget button, then uses the
Left property to move the Currency button to the same position as the
Budget button:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
'Hide the Budget button
Budget.Visible = False
'Move the Currency button to the left
CurrencyButton.Left = Budget.Left
End Sub
Related items
174
V B A
D E V E L O P E R S
G U I D E
O C K E D
P R O P E R T Y
Locked property
Description
The Locked property locks a field. The user cant change the value of a
locked field, but they can view data in the field.
Syntax
field.Locked [= boolean]
Parameters
Comments
A locked field appears with a light gray background, indicating that the
user cant change the contents of the field.
You can set the value of a field youve locked using VBA. You cannot set the
value of a field locked by the accounting system, nor can you unlock a field
locked by the accounting system. Typically, Microsoft Dynamics GP
application code locks fields whose values are necessary to preserve the
integrity of accounting data, such as document totals. You can always
return a locked fields value.
Keep in mind that a locked field is not the same as a disabled field (a field
whose Enabled property is False). If False, the Enabled property makes the
field non-editable, and also dims the fields value, prompt and related
controls.
Examples
Related items
VBA
DEVELOPERS
GUIDE
175
O V E
M E T H O D
Move method
Description
Syntax
Parameters
Comments
You can use named arguments for the Move method, or enter arguments by
position. If you use positional arguments, enter each in the order shown,
using commas and empty string values ("") to indicate the relative position
of arguments you dont specify. Any unspecified arguments remain
unchanged.
Examples
The following example uses named arguments to move the left position of
the field and change the width of the field:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
'Set the left distance and the field width
CustomerID.Move Left: = 10, Width: = 70
End Sub
Related items
176
V B A
D E V E L O P E R S
G U I D E
A M E
P R O P E R T Y
Name property
Description
The Name property specifies the internal name VBA uses to reference a
window field or report field object.
Syntax
field.Name
Parameters
Comments
Examples
Related items
Use the Visual Basic Properties window to change a fields Name property.
Methods and properties
The window objects Name property.
The report objects Name property.
The grid objects Name property.
VBA
DEVELOPERS
GUIDE
177
B J E C T
P R O P E R T Y
Object property
The Object property returns a field object without the standard properties
and methods extended to it by Visual Basic.
Description
Syntax
Parameters
Comments
Method/property
Caption property
Locked property
Empty property
Required property
Enabled property
FocusSeg method
178
V B A
D E V E L O P E R S
G U I D E
B J E C T
P R O P E R T Y
In these cases, the Object property allows you to bypass the VBA-supplied
standard property or method and use the identically-named property or
method defined by the host application.
Since there are no inherent naming conflicts with VBA methods and properties for
field objects, you dont need to use this property when working with field objects.
Examples
The Object property is not relevant for field objects at this time. Refer to the
Visual Basic online help for additional information and examples of the
Object property.
VBA
DEVELOPERS
GUIDE
179
A R E N T
P R O P E R T Y
Parent property
Description
Syntax
field.Parent
Parameters
Comments
Examples
In the following example, two procedures illustrate how to use the Parent
property. The first procedure uses the Call statement to call a sub procedure
named FieldCaption after a Microsoft Dynamics GP window opens. It
passes the windows Customer ID field as an object to the procedure.
The second procedure is a new sub procedure defined for the module. It
receives the Customer ID field object passed from the first procedure. The
procedure then uses the Parent property to ascertain the name of the
window where the field was passed from, and changes the fields caption
based on the windows name:
Private Sub Window_AfterOpen()
'Pass a window field to the FieldCaption procedure
Call FieldCaption(CustomerID)
End Sub
-------------------------------------------------------------------Public Sub FieldCaption(FieldObj As Object)
If FieldObj.Parent.Name = "CustomerMaintenance" Then
CustomerMaintenance.CustomerID.Caption = "Customer No."
ElseIf FieldObj.Parent.Name = "InvoiceEntry" Then
InvoiceEntry.CustomerID.Caption = "Cus. No."
End If
End Sub
180
V B A
D E V E L O P E R S
G U I D E
E Q U I R E D
P R O P E R T Y
Required property
Description
The Required property specifies whether the field must contain data before
the user can save information in the window.
Syntax
field.Required [= boolean]
Parameters
Comments
You cannot set the Required property to False for fields already marked as
required by the accounting system. These are fields necessary for the
system to store the record properly.
If you make a field required, be sure the field is enabled (its
Enabled property is True) and unlocked (its Locked property is False).
Examples
The following example sets the Required property for the Phone 1 field in
the Customer Maintenance window:
Private Sub UserDefined1_AfterUserChanged()
If UserDefined1 = "RETAIL" Then
Phone1.Required = True
Elseif UserDefined1 = "WHOLESALE" Then
Phone1.Required = False
End If
End Sub
VBA
DEVELOPERS
GUIDE
181
A B
T O P
P R O P E R T Y
TabStop property
Description
Syntax
field.TabStop [= boolean]
Parameters
Comments
The tab sequence is the order in which the focus moves through fields when
the user presses the TAB key. Removing a field from the tab sequence
bypasses the field when you press the TAB key. If you add the field back to
the sequence, it maintains its original order in the sequence.
Removing a rarely-used field from the tab sequence allows users to move
from field to field more efficiently. Once you remove a field from the tab
sequence, the user can still place the focus in the field using the mouse. This
setting doesnt affect the users ability to enter data in the field.
Since you cannot place the focus in hidden, locked or disabled fields, the
accounting system ignores these fields in the tab sequence.
Examples
The following example removes three fields from the tab sequence in the
Invoice Entry window:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If UserInfoGet.UserID = "LESSONUSER2" Then
Hold.TabStop = False
BatchID.TabStop = False
CustomerPONumber.TabStop = False
End If
End Sub
182
V B A
D E V E L O P E R S
G U I D E
O P
P R O P E R T Y
Top property
Description
Syntax
field.Top [= integer]
Parameters
Examples
The following example uses the Top property and Left property to move
the Currency1 button field to the same window position as the invisible
Budget button field:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
Budget.Visible = False
Currency1.Top = Budget.Top
Currency1.Left = Budget.Left
End Sub
Related items
VBA
DEVELOPERS
GUIDE
183
A L U E
P R O P E R T Y
Value property
Description
The Value property specifies the value of a window or report field. For
window fields, the Value property is a read/write property. For report
fields, the Value property is a read-only property unless the field is a userdefined calculated field.
Syntax
field.Value [= string_value]
Parameters
Comments
If you omit the Value property from your code, VBA assumes youre
returning or setting the value of the field. The following example explicitly
uses the Value property:
BatchID.Value = "DEBITMEMOS"
The same code can also omit the Value property and be written like this:
BatchID = "DEBITMEMOS"
The following table lists each field type for which you can set or return a
value using the Value property, as well as a description of the string value
used for the field type:
184
V B A
D E V E L O P E R S
Field type
Description
Check box
Combo box
Composite
Currency
Date
Drop-down list
Integer
List box
Long integer
G U I D E
Examples
A L U E
P R O P E R T Y
Field type
Description
Push button
Radio group
String
Time
Visual switch
The following example sets the Sort By list field in the Customer
Maintenance window when the window opens:
Private Sub Window_AfterOpen()
'Set the Sort By list to "By Salesperson ID"
SortBy.Value = 5
End Sub
The following example sets the value of the Batch ID string field when the
user chooses a document type from the Document Type drop-down list:
Private Sub DocumentType_AfterUserChanged()
Select Case DocumentType
'Set the batch ID to one of three existing batches
Case 1
BatchID.Value = "DAILYSLS"
Case 7
BatchID.Value = "DAILYRET"
Case Else
BatchID.Value = "DAILYMISC"
End Select
End Sub
VBA
DEVELOPERS
GUIDE
185
A L U E
P R O P E R T Y
The following example checks the value of the Checkbook ID field, then
sets the value of the Cash Account composite field to an existing account
number. Note that the syntax omits the Value property:
Private Sub CheckbookID_Changed()
If CheckbookID="FIRST NATIONAL" And CashAccount.Enabled=True Then
CashAccount = "100-5100-00"
CashAccount.Enabled = False
ElseIf CheckbookID <> "FIRST NATIONAL" Then
CashAccount.Enabled = True
End If
End Sub
Related items
Additional information
Working with field values and Window field type reference in Chapter 3, Programming
Window Fields.
186
V B A
D E V E L O P E R S
G U I D E
A L U E
E G
P R O P E R T Y
ValueSeg property
Description
Syntax
Parameters
Comments
Use the ValueSeg property to set or return segment values after the
composite gains focus (using the BeforeGotFocus, AfterGotFocus or
BeforeUserChanged events). The composite gains focus when the user
moves to the composite field, or when you programatically move the focus
using the Focus method or FocusSeg method.
Examples
The following procedure moves the focus to the Cash Account field using
the FocusSeg method:
Private Sub CheckbookID_BeforeUserChanged(KeepFocus _
As Boolean, CancelLogic As Boolean)
CashAccount.FocusSeg (1)
End Sub
Once the Cash Account has focus, a BeforeGotFocus event procedure sets
the value of the segments in the composite using the ValueSeg property:
Private Sub CashAccount_BeforeGotFocus(CancelLogic As Boolean)
If CheckbookID = "CO. PAYROLL" Then
CashAccount.ValueSeg(1) = "000"
CashAccount.ValueSeg(2) = "21"
CashAccount.FocusSeg (2)
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
187
I S I B L E
P R O P E R T Y
Visible property
Description
Syntax
field.Visible [= boolean]
Parameters
Comments
If you hide a window field using the Visible property, VBA hides both the
field and its caption. You can still return or set the values of fields you make
invisible with VBA. However, you cannot set the value of fields hidden by
the accounting system, nor can you show these fields.
Examples
The following example hides sales fields when a user opens the Salesperson
Maintenance window:
Private Sub Window_AfterOpen()
If UserInfoGet.UserID = "LESSONUSER1" Then
CommissionedSales.Visible = False
CostofSales.Visible = False
NonCommissionedSales.Visible = False
TotalCommissions.Visible = False
End If
End Sub
Related items
Events
The window objects BeforeOpen event.
188
V B A
D E V E L O P E R S
G U I D E
I D T H
P R O P E R T Y
Width property
Description
Syntax
field.Width [= integer]
Parameters
Comments
The Width property calculates the fields width starting at the left edge of
the field, and sizes the field to the specified width. The Width property
doesnt affect the fields caption.
Examples
The following example changes the width of several fields in the Invoice
Entry window:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
TradeDiscount.Width = 140
Freight.Width = 140
Miscellaneous.Width = 140
Tax.Width = 140
Total.Width = 140
End Sub
Related items
VBA
DEVELOPERS
GUIDE
189
190
V B A
D E V E L O P E R S
G U I D E
Chapter 10:
Grid Object
Your project uses the grid object to perform several tasks related to working
with grids (scrolling windows). The events, methods and properties that
apply to the grid object are listed below. A detailed explanation of each
follows:
AfterLineChange event
AfterLineGotFocus event
AfterLineLostFocus event
BeforeLineChange event
BeforeLineGotFocus event
BeforeLineLostFocus event
BeforeLinePopulate event
Changed property
EventMode property
Hide method
Left property
Move method
Name property
Show method
Top property
Visible property
VBA
DEVELOPERS
GUIDE
191
F T E R
I N E
H A N G E
E V E N T
AfterLineChange event
Description
Syntax
grid_AfterLineChange()
Parameters
Comments
Examples
192
V B A
D E V E L O P E R S
G U I D E
F T E R
I N E
O T
O C U S
E V E N T
AfterLineGotFocus event
Description
The AfterLineGotFocus event occurs when the focus moves to a new line
in a grid. It occurs after the Microsoft Dynamics GP line got focus event.
Syntax
grid_AfterLineGotFocus()
Parameters
Comments
Examples
VBA
DEVELOPERS
GUIDE
193
F T E R
I N E
O S T
O C U S
E V E N T
AfterLineLostFocus event
Description
The AfterLineLostFocus event occurs when the focus moves out of a line. It
occurs after the Microsoft Dynamics GP line lost focus event.
Syntax
grid_AfterLineLostFocus()
Parameters
Comments
Microsoft Dynamics GP rarely uses the line lost focus event. Whether you
choose the VBA AfterLineLostFocus or BeforeLineLostFocus event is of
little consequence.
Examples
194
V B A
D E V E L O P E R S
G U I D E
E F O R E
I N E
H A N G E
E V E N T
BeforeLineChange event
Description
Syntax
grid_BeforeLineChange(KeepFocus As Boolean)
Parameters
Comments
Use the BeforeLineChange event to check the value of fields in a line, then
cancel subsequent line change events if criteria you specify arent met.
Examples
VBA
DEVELOPERS
GUIDE
195
E F O R E
I N E
O T
O C U S
E V E N T
BeforeLineGotFocus event
Description
The BeforeLineGotFocus event occurs when the focus moves to a new line
in a grid. It occurs before the Microsoft Dynamics GP line got focus event.
Syntax
grid_BeforeLineGotFocus()
Parameters
Comments
Examples
196
V B A
D E V E L O P E R S
G U I D E
E F O R E
I N E
O S T
O C U S
E V E N T
BeforeLineLostFocus event
Description
The BeforeLineLostFocus event occurs when the focus moves out of a line.
It occurs before the Microsoft Dynamics GP line lost focus event.
Syntax
grid_BeforeLineLostFocus()
Parameters
Comments
Microsoft Dynamics GP rarely uses the line lost focus event. Whether you
choose the VBA AfterLineLostFocus or BeforeLineLostFocus event is of
little consequence.
Examples
VBA
DEVELOPERS
GUIDE
197
E F O R E
I N E
O P U L A T E
E V E N T
BeforeLinePopulate event
Description
Syntax
grid_BeforeLinePopulate(RejectLine As Boolean)
Parameters
Comments
Examples
198
V B A
D E V E L O P E R S
G U I D E
H A N G E D
P R O P E R T Y
Changed property
Description
Syntax
grid.Changed [= boolean]
Parameters
Comments
A grid line changes when the value changes in one of the lines fields. If this
occurs, the Changed property will return True for the current line (the line
with focus) in the grid.
The Changed property is useful for determining whether the contents of a
line changed, and performing an action based on those changes.
Examples
The following example displays a message containing the date and time
when a line in a sales transaction record was changed. This information
could also be added to the DUOS or to another database (such as Microsoft
Access) and stored with the transaction record:
Private Sub Grid_AfterLineChange()
If SalesTransactionEntryDetail.Changed Then
MsgBox "This item changed on " & Date & " at " & Time & "."
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
199
V E N T
O D E
P R O P E R T Y
EventMode property
Description
The EventMode property specifies whether VBA grid events occur for the
original or modified version of the grid.
Syntax
grid.EventMode [= mode]
Parameters
Comments
Constant
Description
emOriginalOnly
Grid events occur only for the original version of the grid.
emModifiedOnly
emNever
Examples
Typically, you set the grids EventMode property using the Visual Basic
Properties window. You can also set it through an event procedure, as
shown in the following example:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If CustomersandProspects.Caption = ".Customers and Prospects." _
Then
'Shut off events for the window and the grid.
CustomersandProspects.EventMode = emOriginalOnly
CustomersandProspectsDetail.EventMode = emOriginalOnly
End If
End Sub
Related items
200
V B A
D E V E L O P E R S
G U I D E
I D E
M E T H O D
Hide method
Description
Syntax
grid.Hide
Parameters
Comments
Examples
The following example hides the grid on the Sales Transaction Entry
window when the window opens. The rest of the window (the windows
header fields, and the windows summary fields) are still visible:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
SalesTransactionEntryDetail.Hide
End Sub
Related items
VBA
DEVELOPERS
GUIDE
201
E F T
P R O P E R T Y
Left property
Description
The Left property specifies the horizontal position of the grid (in pixels)
relative to the left edge of the window containing the grid.
Syntax
grid.Left [= integer]
Parameters
Comments
The Left property will specify the distance to the left edge of the window
for the grid and any of the fields, prompts and controls associated with the
grid. These items are associated with the grid if theyre no further than one
pixel from the grids border, or if theyre one pixel from the edge of another
associated item.
Most grids in Microsoft Dynamics GP are positioned 8 pixels to the left of
the windows left edge.
Examples
The following example positions the left edge of the grid 20 pixels from the
left edge of the window using the Left property:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
CustomersandProspectsDetail.Left = 20
End Sub
Related items
202
V B A
D E V E L O P E R S
G U I D E
O V E
M E T H O D
Move method
Description
The Move method changes the position of a grid relative to the window
containing the grid.
Syntax
Parameters
Comments
You can use named arguments for the Move method, or specify arguments
by position. If you use positional arguments, enter each in the order shown,
using commas and null string values ("") to indicate the relative position of
arguments you dont specify.
The Move method will move the grid and any of the fields, prompts and
controls associated with the grid. These items are associated with the grid if
theyre no further than one pixel from the grids border, or if theyre one
pixel from the edge of another associated item.
Examples
The following example uses named arguments to change the height of the
grid when the Customers and Prospects lookup window opens:
Private Sub Window_AfterOpen()
CustomersandProspectsDetail.Move Height:= 300
End Sub
The following example positions the grid in the Customers and Prospects
lookup window using positional arguments. It sets only the first two
parameters:
Private Sub Window_AfterOpen()
CustomersandProspects.Move 10,20,"",""
End Sub
VBA
DEVELOPERS
GUIDE
203
O V E
M E T H O D
Related items
204
V B A
D E V E L O P E R S
G U I D E
A M E
P R O P E R T Y
Name property
Description
The Name property specifies the internal name VBA uses to reference a
grid object.
Syntax
grid.Name
Parameters
Comments
Examples
Related items
To change a grids Name property, use the Visual Basic Properties window.
Methods and properties
The fied objects Name property.
The window objects Name property.
The report objects Name property.
VBA
DEVELOPERS
GUIDE
205
H O W
M E T H O D
Show method
Description
Syntax
grid.Show
Parameters
Comments
Use the Show method to make visible any grid thats currently invisible.
The Hide method and Visible property make a grid invisible.
Examples
The following example shows a grid thats been hidden using either the
Hide method or the Visible property:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If UserInfoGet.UserID <> "LESSONUSER1" Then
SalesTransactionEntryDetail.Show
End If
End Sub
Related items
206
V B A
D E V E L O P E R S
G U I D E
O P
P R O P E R T Y
Top property
Description
The Top property specifies the vertical position of the grid relative to the
bottom border of the windows title bar.
Syntax
grid.Top [= integer]
Parameters
Comments
The Top property will move the grid and any of the fields, prompts and
controls associated with the grid. These items are associated with the grid if
theyre no further than one pixel from the grids border, or if theyre one
pixel from the edge of another associated item.
Examples
The following example changes the top position of the grid so it now
appears below a new field, Sort By State, in the Customers and Prospects
lookup window:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
CustomersandProspectsDetail.Top = SortByState.Top + _
SortByState.Height + 6
End Sub
Related items
VBA
DEVELOPERS
GUIDE
207
I S I B L E
P R O P E R T Y
Visible property
Description
Syntax
grid.Visible [= boolean]
Parameters
Comments
While invisible, data in a grid is still accessible. Use this property when you
want to reference data displayed in the grid without making the grid
visible. You can also make a grid invisible using the Hide method.
Examples
The following example hides the grid in the Sales Transaction Entry
window based on the current user:
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
If UserInfoGet.UserID = "LESSONUSER1" Then
SalesTransactionEntryDetail.Visible = False
End If
End Sub
Related items
208
V B A
D E V E L O P E R S
G U I D E
Chapter 11:
Report Object
Your project uses the report object to perform several tasks related to
working with reports. The events, methods and properties that apply to the
report object are listed below. A detailed explanation of each follows:
BeforeAF event
BeforeAH event
BeforeBody event
BeforePF event
BeforePH event
BeforeRF event
BeforeRH event
Cancel method
End event
EventMode property
Legend property
Name property
Start event
VBA
DEVELOPERS
GUIDE
209
E F O R E
A F
E V E N T
BeforeAF event
Description
The BeforeAF event occurs before each instance of the specified additional
footer prints.
Syntax
Parameters
Comments
Examples
210
V B A
D E V E L O P E R S
G U I D E
E F O R E
A H
E V E N T
BeforeAH event
Description
The BeforeAH event occurs before each instance of the specified additional
header prints.
Syntax
Parameters
Comments
Examples
In the following example, the BeforeAH event procedure sets the Level
parameter to 2, indicating that the procedure runs for the second additional
header on a report. The procedure then checks the value of the Checkbook
ID field in the second additional header:
Private Sub Report_BeforeAH(By Val Level As Integer, SuppressBand _
As Boolean)
If Level = 2 Then
If CheckbookID = "PAYROLL" Then
BankDepositPostingJournal.Cancel
End If
End If
End Sub
VBA
DEVELOPERS
GUIDE
211
E F O R E
O D Y
E V E N T
BeforeBody event
Description
The BeforeBody event occurs before each instance of the reports body
prints.
Syntax
report_BeforeBody(SuppressBand As Boolean)
Parameters
Comments
Examples
The following example uses the BeforeBody event to return the value of the
Commissioned Sales field in the current body record of the RM Salesperson
Report. If a salespersons commissioned sales are less than $200,000, the
SuppressBand parameter stops the current body record from printing. The
result is that the report prints only records for salespeople whove exceeded
$200,000 in commissioned sales:
Private Sub Report_BeforeBody(SuppressBand As Boolean)
If CCur(CommissionedSalesToDate) < 200000 Then
SuppressBand = True
End If
End Sub
212
V B A
D E V E L O P E R S
G U I D E
E F O R E
P F
E V E N T
BeforePF event
Description
The BeforePF event occurs before the reports page footer prints.
Syntax
report_BeforePF(SuppressBand As Boolean)
Parameters
Comments
Use the BeforePF event to reference fields in a reports page footer. Items in
the page footer are placed at the bottom of every report page. The page
footer often includes administrative information, such as the name of the
person running the report.
Examples
VBA
DEVELOPERS
GUIDE
213
E F O R E
P H
E V E N T
BeforePH event
Description
The BeforePH event occurs before the reports page header prints.
Syntax
report_BeforePH(SuppressBand As Boolean)
Parameters
Comments
Use the BeforePH event to reference fields in a reports page header. Items
in the page header are placed at the top of every report page. Page number,
date and time fields are commonly placed in this section of a report.
Examples
214
V B A
D E V E L O P E R S
G U I D E
E F O R E
R F
E V E N T
BeforeRF event
Description
The BeforeRF event occurs before the reports report footer prints.
Syntax
report_BeforeRF(SuppressBand As Boolean)
Parameters
Comments
Use the BeforeRF event to reference fields in the report footer. Summary
information is often included in the report footer. If a page footer is also
included on the last page, the report footer will print before the page footer.
Examples
VBA
DEVELOPERS
GUIDE
215
E F O R E
R H
E V E N T
BeforeRH event
Description
The BeforeRH event occurs before the reports report header prints.
Syntax
report_BeforeRH(SuppressBand As Boolean)
Parameters
Comments
Use the BeforeRH event to reference fields in the report header. Items in the
report header appear only on the first page of a report. If a page header is
also included on the first page, the report header will appear after the page
header.
Microsoft Dynamics GP typically uses fields in the report header that you
cant reference from the BeforeRH event; such as system variables that
show the page number, user ID and company name, and legend fields that
show the record ranges for the report. Microsoft Dynamics GP rarely uses
table fields or calculated fields in the report header.
Examples
216
V B A
D E V E L O P E R S
G U I D E
A N C E L
M E T H O D
Cancel method
Description
Syntax
report.Cancel
Parameters
Comments
The Cancel method stops the report from printing. If canceled from a report
band event, data from that band will print before the report stops. If the
report prints to the screen, the Cancel method automatically closes the
Screen Output window. The End event occurs after you cancel a report
using the Cancel method.
Examples
cancels
report
from
the
reports
Related items
Events
The report objects End event.
VBA
DEVELOPERS
GUIDE
217
N D
E V E N T
End event
Description
Syntax
report_End()
Parameters
Comments
Use the End event to perform any clean-up of activities for the report,
launch other applications, or open and close other windows. The End event
will always run if a reports Start event occurs, including when a report is
canceled using the Cancel method.
Examples
Related items
Events
The report objects Start event.
218
V B A
D E V E L O P E R S
G U I D E
V E N T
O D E
P R O P E R T Y
EventMode property
Description
The EventMode property specifies whether report events occur for the
original or modified version of the report.
Syntax
report.EventMode [= mode]
Parameters
Description
emOriginalOnly
emModifiedOnly
emNever
Comments
If you modify a report using the Report Writer, you must set the
EventMode property to emModified if you want VBA events to occur for
the modified report. To change the EventMode property for the report
object, use the Visual Basic Properties window.
Examples
Typically, you set the reports EventMode property using the Visual Basic
Properties window. You can also set it through an event procedure, as
shown in the following example:
Private Sub Report_Start()
If UserInfoGet.UserID = "LESSONUSER1" Then
RMCustomerReport.EventMode = emOriginalOnly
End If
End Sub
Related items
VBA
DEVELOPERS
GUIDE
219
E G E N D
P R O P E R T Y
Legend property
Description
Syntax
report.Legend(index) [= string_value]
Parameters
Comments
Legends are fields whose data is persistent throughout the report, and must
be passed to the report as it starts. You must use the Legend property in the
reports Start event to set or return the value of a legend field in a report.
Legend fields typically include information about the report, such as the
range of records the user chose for the report. The following illustration
shows legend fields in the RM Customer Report used to show the range of
customer records that print for the report.
You dont add a legend field to your project; instead, you use the Legend
propertys index parameter to refer to a specific legend field on the report.
Examples
The following Start event procedure returns the value of the Customer
Class legend field using the fields index:
Private Sub Report_Start()
If RMCustomerReport.Legend(5) = "AARONFIT0001 - AARONFIT0001" Then
RMCustomerReport.Cancel
End If
Related items
Events
The report objects Start event.
220
V B A
D E V E L O P E R S
G U I D E
A M E
P R O P E R T Y
Name property
Description
The Name property specifies the internal name VBA uses to reference a
report object.
Syntax
report.Name
Parameters
Comments
Examples
Related items
VBA
DEVELOPERS
GUIDE
221
T A R T
E V E N T
Start event
Description
The Start event occurs as the report starts to print, but before any data
actually prints.
Syntax
report_Start()
Parameters
Comments
Use the Start event to set any report legends using the Legend property.
Legends are fields whose data is persistent throughout the report, and must
be passed to the report as it starts.
Examples
The following example sets the value of a legend field from the Start event:
Private Sub Report_Start()
RMCustomerReport.Legend(2) = "Aging Period Amount"
End Sub
Related items
Events
The report objects End event.
222
V B A
D E V E L O P E R S
G U I D E
Chapter 12:
VBAGlobal Object
Your project uses the VBAGlobal object to perform tasks related to the
Dynamic User Object Store (DUOS). It also provides a method to retrieve
the UserInfo object used to access information about the current user. The
methods that apply to the VBAGlobal object are listed below. A detailed
explanation of each follows:
DUOSObjectCombineID method
DUOSObjectExtractID method
DUOSObjectsGet method
UserInfoGet method
VBA
DEVELOPERS
GUIDE
223
DUO SO
B J E C T
ID
O M B I N E
M E T H O D
DUOSObjectCombineID method
Description
Syntax
DUOSObjectsCombineID(string1, string2)
Parameters
Return value
Comments
Data objects you define in the DUOS must have a unique object ID within a
collection. If you create a data object with an object ID that already exists in
the collection, the new data object will overwrite the existing object. To
avoid duplicate object IDs, create a unique ID using this method.
In most cases, you can assign the value of a Microsoft Dynamics GP control
field as the objects ID. A control field, such as a customer ID or a document
number, controls the display of a record in a window, and is a unique value
in the accounting system.
Examples
The following procedure runs when the user clicks the Save button in the
Item Vendors Maintenance window. It uses the DUOSObjectsCombineID
method to combine the values of two window fields (Vendor ID and Item
Number) to construct a unique object ID:
Private Sub Save_BeforeUserChanged(KeepFocus As Boolean, _
CancelLogic As Boolean)
Dim VendorCollection As DUOSObjects
Dim VendorObject As DUOSObject
Dim ObjectID As String
'Specify a vendors collection
Set VendorCollection = DUOSObjectsGet("Vendors")
'Combine two field values to create a unique object ID
ObjectID = DUOSObjectCombineID(VendorID, ItemNumber)
'Create the object, using the combined ID
Set VendorObject = Vendors.Item(ObjectID)
'Set the objects properties using window fields
VendorObject.Properties("Discount Quantity") = DiscountQuantity
VendorObject.Properties("Discount Percent") = DiscountPercent
End Sub
224
V B A
D E V E L O P E R S
G U I D E
D U O S O
Related items
B J E C T
O M B I N E
I D
M E T H O D
VBA
DEVELOPERS
GUIDE
225
DUO SO
B J E C T
ID
X T R A C T
M E T H O D
DUOSObjectExtractID method
Description
Syntax
Parameters
226
Return value
Comments
V B A
D E V E L O P E R S
G U I D E
D U O S O
Examples
B J E C T
X T R A C T
I D
M E T H O D
The following example uses a button on a VBA user form to loop through a
collection named Vendors. It uses the DUOSObjectExtractID method to
check whether each data objects objectID is combined. Any object with a
combined objectID uses an ID composed of the vendors ID and the vendor
type. If the vendor type (ventype) is PREFERRED, the procedure updates
the properties for the data object:
Private Sub CommandButton1_Click()
Dim VendorCollection As DUOSObjects
Dim VendorObject As DUOSObject
Dim ObjectID As String
Dim venID As String
Dim ventype As String
'Return a vendors collection
Set VendorCollection = DUOSObjectsGet("Vendors")
For Each VendorObject In VendorCollection
If DUOSObjectExtractID(VendorObject.ID, venID, ventype) _
= True Then
'This is a combined ID. Update with new discount info.
If ventype = "PREFERRED" Then
'Update the properties for this vendor
VendorObject.Properties("Discount Quantity") = "200"
VendorObject.Properties("Discount Percent") = "6.50"
End If
End If
Next
End Sub
Related items
VBA
DEVELOPERS
GUIDE
227
DUO SO
B J E C T S
E T
M E T H O D
DUOSObjectsGet method
Description
Syntax
DUOSObjectsGet(collection_name)
collection_name A string specifying the collection youre working with. If
the specified collection_name doesnt exist for the current company, this
method creates it.
Parameters
Return value
Comments
"Customers"
Collection
"Vendors"
Collection
"Items"
Collection
If the collection_name specified does not exist, this method creates the
collection with that collection_name.
DUOSObjectsGet("Employees")
"Customers"
Collection
"Vendors"
Collection
"Items"
Collection
"Employees"
Collection
228
V B A
D E V E L O P E R S
G U I D E
DUO SO
Examples
B J E C T S
E T
M E T H O D
VBA
DEVELOPERS
GUIDE
229
S E R
N F O
E T
M E T H O D
UserInfoGet method
Description
Syntax
UserInfoGet(collection_name)
Parameters
None
Return value
Examples
The following example retrieves the UserInfo object, and then displays the
current companys name in a message box.
Dim UserInfoObj As UserInfo
Dim CompanyName As String
'Get the UserInfo object
Set UserInfoObj = VbaGlobal.UserInfoGet()
'Retrieve and display the company name
CompanyName = UserInfoObj.CompanyName
MsgBox CompanyName
Related items
230
V B A
D E V E L O P E R S
G U I D E
Chapter 13:
DUOSObjects Collection
Your project uses the DUOSObjects collection to perform several tasks
related to creating and maintaining a collection of objects in the Dynamic
User Object Store (DUOS). The methods and properties that apply to a
DUOSObjects collection are listed below. A detailed explanation of each
follows:
Exists property
Item property
Name property
Remove method
SortByExisting property
VBA
DEVELOPERS
GUIDE
231
X I S T S
P R O P E R T Y
Exists property
Description
Syntax
DUOSObjects.Exists(objectID)
Parameters
Comments
Examples
In the following example, the Changed event procedure runs for the Total
field when the user changes an invoice amount in the Invoice Entry
window. The procedure uses the Exists property to ascertain whether a
corresponding invoice object already exists in the collection. If it does exist,
the procedure updates it with the current system date using the VBA Date()
function:
Private Sub Total_Changed()
Dim InvoiceCollection As DUOSObjects
Dim InvoiceObject As DUOSObject
Set InvoiceCollection = DUOSObjectsGet("Invoices")
If InvoiceCollection.Exists(DocumentNumber) Then
'A data object for this invoice exists
'Set a property to indicate the user changed the total
InvoiceObject.Properties("Invoice Adjustment Date") = Date
End If
End Sub
232
V B A
D E V E L O P E R S
G U I D E
T E M
P R O P E R T Y
Item property
Description
Syntax
DUOSObjects.Item(objectID)
Parameters
Comments
Examples
The following procedure runs when the user clicks a button in a VBA user
form. It returns a collection named Item Info, then uses the Item property to
return a data object with an objectID matching the Item Number in the Item
Maintenance window. The Set statement assigns the returned data object to
an object variable named ItemObject. The Remove method then deletes the
object returned by the Item property:
Private Sub DeleteItem_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Set ItemCollection = DUOSObjectsGet("ItemInfo")
'Specify a data object using a window field value
Set ItemObject = ItemCollection.Item(ItemMaintenance.ItemNumber)
ItemCollection.Remove(ItemMaintenance.ItemNumber)
End Sub
VBA
DEVELOPERS
GUIDE
233
A M E
P R O P E R T Y
Name property
Description
Syntax
DUOSObjects.Name
Parameters
Comments
Use the Name property to identify the name of a collection object returned
by the DUOSObjectsGet method. You can use the Name property to
distinguish between multiple collections in the same procedure.
Examples
The following procedure runs when the user clicks a button in a VBA user
form. The Name property returns the name of the collection object returned
by the DUOSObjectsGet method:
Private Sub CommandButton_Click()
Dim Collection As DUOSObjects
Dim ItemObject As DUOSObject
If CustomerMaintenance.IsLoaded Then
Set Collection = DUOSObjectsGet("Customers")
Else
Set Collection = DUOSObjectsGet("Items")
End If
'Display either "Customers" or "Items"
MsgBox "The current collection is " + Collection.Name
End Sub
Related items
234
V B A
D E V E L O P E R S
G U I D E
E M O V E
M E T H O D
Remove method
Description
Syntax
DUOSObjects.Remove(objectID)
Parameters
Examples
The following procedure runs when the user clicks a button in a VBA user
form. The procedure loops through a collection named Item Info and checks
the Item Color property for each item. If the value is Red, the collections
Remove method deletes the data object:
Private Sub CommandButton_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Set ItemCollection = DUOSObjectsGet("Item Info")
For Each ItemObject In ItemCollection
If ItemObject.Properties.Item("Item Color") = "Red" Then
'Delete the object
ItemCollection.Remove (ItemObject.ID)
End If
Next
End Sub
VBA
DEVELOPERS
GUIDE
235
O R T
X I S T I N G
P R O P E R T Y
SortByExisting property
Description
Syntax
DUOSObjects.SortByExisting [= property_name]
Parameters
Comments
Object
ID
Property name
Property value
Customers
C001
C005
Date Added
03/22/96
Date Added
01/04/96
URL Address
www.afitz.com
C002
Date Added
12/18/95
URL Address
www.altonmfg.com
C001
Date Added
04/13/95
In this case, the items are sorted in ascending order starting with the most
recent date. If the property_name exists only for a subset of objects in the
collection, the collection will be restricted to that subset of objects. In the
following example, the SortByExisting method sorts by the URL Address
property:
Collection
name
Object
ID
Property name
Property value
Customers
C005
Date Added
01/04/96
URL Address
www.afitz.com
C002
236
V B A
D E V E L O P E R S
G U I D E
Date Added
12/18/95
URL Address
www.altonmfg.com
Examples
O R T
X I S T I N G
P R O P E R T Y
The following procedure runs when the user clicks a button added to the
Customer Maintenance window using the Modifier. It uses the
SortByExisting method to sort the CustomerCollection by the collections
Date Added property. It then creates a report file using the VBA Open
statement, and prints the objects ID, property names and property values
to the file using the VBA Print# statement. Only data objects that include
the Date Added property will be printed, and will be sorted by date:
Private Sub PrintByDateButton_AfterUserChanged()
Dim CustomerCollection As DUOSObjects
Dim CustomerObject As DUOSObject
Dim CustomerProperty As DUOSProperty
Dim CustomerProperties As DUOSProperties
Set CustomerCollection = DUOSObjectsGet("CustomerCollection")
'Sort the collection by the date the customer was added
CustomerCollection.SortByExisting = "Date Added"
'Create a text file for the report
Open "CustomerReport.txt" For Output As #1
For Each CustomerObject In CustomerCollection
Print #1, CustomerObject.ID
Set CustomerProperties = CustomerObject.Properties
For Each CustomerProperty In CustomerObject.Properties
Print #1, " " + CustomerProperty.Name + " - " + _
CustomerProperty.Value
Next
Next
End Sub
VBA
DEVELOPERS
GUIDE
237
238
V B A
D E V E L O P E R S
G U I D E
Chapter 14:
DUOSObject Object
Your project uses the DUOSObject object to perform several tasks related to
creating and maintaining a data object in the Dynamic User Object Store
(DUOS). The properties that apply to the DUOSObject object are listed
below. A detailed explanation of each follows:
ID property
Properties property
VBA
DEVELOPERS
GUIDE
239
I D
P R O P E R T Y
ID property
Description
Syntax
DUOSObject.ID
Parameters
Comments
Examples
The following procedure runs when the user clicks a button in a VBA user
form. The procedure loops through the collection named Item Info and
checks the Item Color property for each item. If the value is Red, the
collections Remove method deletes the object indicated by the ID
property:
Private Sub CommandButton_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Set ItemCollection = DUOSObjectsGet("Item Info")
For Each ItemObject In ItemCollection
If ItemObject.Properties.Item("Item Color") = "Red" Then
'Delete the object
ItemCollection.Remove (ItemObject.ID)
End If
Next
End Sub
240
V B A
D E V E L O P E R S
G U I D E
R O P E R T I E S
P R O P E R T Y
Properties property
Description
Syntax
DUOSObject.Properties
Parameters
Comments
You can use the Properties property in combination with the Item property
to specify a named property for the object. In most cases, this is the
preferred way to set or return a propertys value.
Examples
The following procedure runs when the user clicks a button in a VBA user
form. This example returns a collection of properties for the current data
object:
Private Sub CommandButton_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
'Specify the collection
Set ItemCollection = DUOSObjectsGet("Additional Item Info")
'Specify an object in the collection with a unique object ID
Set ItemObject = ItemCollection.Item("ITM002")
'Get properties for the object
ItemProperties = ItemObject.Properties
End Sub
VBA
DEVELOPERS
GUIDE
241
242
V B A
D E V E L O P E R S
G U I D E
Chapter 15:
DUOSProperties Collection
Your project uses the DUOSProperties collection to perform several tasks
related to creating and maintaining properties for data objects in the
Dynamic User Object Store (DUOS). The methods and properties that apply
to the DUOSProperties collection are listed below. A detailed explanation of
each follows:
Count property
Exists property
Item property
Remove method
VBA
DEVELOPERS
GUIDE
243
O U N T
P R O P E R T Y
Count property
Description
Syntax
DUOSProperties.Count
Parameters
Comments
The Count property is useful when you want to perform any DUOS
maintenance activities, such as removing unwanted properties, or adding
properties to a data object if it doesnt have the correct number of
properties.
Examples
The following example uses the Count property to return the number of
properties for a given data object. If the number of properties is greater than
2, the procedure loops through the collection, and uses the Remove method
to delete properties other than Item Weight and Item Color:
Private Sub DeleteExtraProperties_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Dim ItemProperty As DUOSProperty
Set ItemCollection = DUOSObjectsGet("ItemInfo")
Set ItemObject = ItemCollection(ItemNumber)
Set ItemProperties = ItemObject.Properties
If ItemProperties.Count > 2 Then
'There are too many properties for this object
'Remove any other than Item Weight and Item Color
For Each ItemProperty In ItemProperties
If Not ((ItemProperty.Name = "Item Weight") Or _
(ItemProperty.Name = "Item Color")) Then
ItemProperties.Remove (ItemProperty)
End If
Next
End If
End Sub
244
V B A
D E V E L O P E R S
G U I D E
X I S T S
P R O P E R T Y
Exists property
Description
Syntax
DUOSProperties.Exists(property_name)
Parameters
Examples
The following procedure runs for a button in a VBA user form. It uses the
Exists property to check whether the Item Color property exists for a given
data object. If the property doesnt exist, the procedure creates it using the
collections Item property:
Private Sub CheckItemColor_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Set ItemCollection = DUOSObjectsGet("ItemCollection")
Set ItemObject = ItemCollection(ItemNumber)
Set ItemProperties = ItemObject.Properties
If ItemProperties.Exists("Item Color") = False Then
'This item has no color property
ItemProperties.Item("Item Color") = InputBox("Enter a " + _
"color for this item.")
'Set the window field
ItemColor = ItemProperties.Item("Item Color")
End If
End Sub
VBA
DEVELOPERS
GUIDE
245
T E M
P R O P E R T Y
Item property
Description
Syntax
DUOSProperties.Item(index)
Parameters
Comments
If you reference the property position in the index, the position starts at 1 for
the first property in the data object. The order you added the property to
the data object determines the property objects position.
If you reference the property name in the index, and the name does not
exist, the Item property creates a property in the collection with that name.
The Item property is the default member of the DUOSProperties collection.
If you omit the Item property from your VBA code, the collection assumes
youre returning the property for the specified properties collection. The
following example includes the Item property:
ItemProperties.Item("Item Color")
246
V B A
D E V E L O P E R S
G U I D E
Examples
T E M
P R O P E R T Y
The following procedure runs when the user clicks a button in a VBA user
form. It loops through a properties collection and uses the Item property to
check the property named Item Weight:
Private Sub UpdateItemLocation_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Dim ItemProperty As DUOSProperty
Set ItemCollection = DUOSObjectsGet("ItemCollection")
For Each ItemObject In ItemCollection
For Each ItemProperty In ItemProperties
If ItemProperties.Item("Item Weight") > "100.00" Then
'The item is greater than 100 pounds
ItemProperties.Item("Storage Location") = _
"Bulk Item Area"
End If
Next
Next
End Sub
In this example, the Item property references the position of the property
rather than the name:
Private Sub CommandButton_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
'Specify the collection
Set ItemCollection = DUOSObjectsGet("Additional Item Info")
'Specify an object in the collection with a unique object ID
Set ItemObject = ItemCollection.Item("ITM002")
'Get properties for the object
ItemObject.Properties(3) = "3.5"
End Sub
VBA
DEVELOPERS
GUIDE
247
E M O V E
M E T H O D
Remove method
Description
Syntax
DUOSProperties.Remove(index)
Parameters
Examples
The following procedure runs when the user clicks a button in a VBA user
form. It removes a property object from a properties collection using the
Remove method:
Private Sub RemoveColorProperty_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Set ItemCollection = DUOSObjectsGet("ItemInfo")
Set ItemObject = ItemCollection(ItemNumber)
Set ItemProperties = ItemObject.Properties
If ItemProperties.Exists("Item Color") Then
ItemProperties.Remove("Item Color")
End If
End Sub
248
V B A
D E V E L O P E R S
G U I D E
Chapter 16:
DUOSProperty Object
Your project uses the DUOSProperty object to perform tasks related to a
property for an object in the Dynamic User Object Store (DUOS). The
properties that apply to the DUOSProperty object are listed below. A
detailed explanation of each follows:
Name property
Value property
VBA
DEVELOPERS
GUIDE
249
A M E
P R O P E R T Y
Name property
Description
The Name property specifies the name of a property for a data object.
Syntax
DUOSProperty.Name
Parameters
Examples
The following procedure runs when the user clicks a button in a VBA user
form. It uses the Name property with the DUOSProperties Remove
method to delete properties for a data object other than Item Weight and
Item Color:
Private Sub DeleteExtraProperties_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Dim ItemProperty As DUOSProperty
Set ItemCollection = DUOSObjectsGet("ItemInfo")
Set ItemObject = ItemCollection(ItemNumber)
Set ItemProperties = ItemObject.Properties
'Remove properties other than Item Weight and Item Color
For Each ItemProperty In ItemProperties
If Not ((ItemProperty.Name = "Item Weight") Or _
(ItemProperty.Name = "Item Color")) Then
ItemProperties.Remove (ItemProperty)
End If
Next
End Sub
250
V B A
D E V E L O P E R S
G U I D E
A L U E
P R O P E R T Y
Value property
Description
Syntax
DUOSProperty.Value [= string_value]
Parameters
Comments
When you set the value of a property object using the Value property, you
cannot exceed 132 characters. The DUOS stores and returns property values
as strings.
The Value property is the default member of the DUOSProperty object. If
you omit the Value property from your VBA code, the object assumes
youre returning the value of the specified property object. The following
example includes the Value property:
ItemProperty.Value = "Red"
VBA
DEVELOPERS
GUIDE
251
A L U E
P R O P E R T Y
Examples
The following example runs when the user clicks a button in a VBA user
form. The procedure loops through a collection named Item Info and uses
the Value property to set the value of the Item Color property for all data
objects:
Private Sub UpdateItemColor_Click()
Dim ItemCollection As DUOSObjects
Dim ItemObject As DUOSObject
Dim ItemProperties As DUOSProperties
Dim ItemProperty As DUOSProperty
Set ItemCollection = DUOSObjectsGet("Item Info")
'Update the item color for all objects in the collection
For Each ItemObject In ItemCollection
For Each ItemProperty In ItemObject.Properties
If ItemProperty.Name = "Item Color" Then
ItemProperty.Value = "Red"
End If
Next
Next
End Sub
Related items
252
V B A
D E V E L O P E R S
G U I D E
Chapter 17:
UserInfo Object
The UserInfo object contains information about the user currently logged
into Microsoft Dynamics GP. The properties and method that apply to the
UserInfo object are listed below. A detailed explanation of each follows:
CompanyName property
CreateADOConnection method
IntercompanyID property
UserDate property
UserID property
UserName property
VBA
DEVELOPERS
GUIDE
253
O M P A N Y
A M E
P R O P E R T Y
CompanyName property
Description
The CompanyName property contains the name of the company that the
user is currently logged into in Microsoft Dynamics GP.
Syntax
UserInfo.CompanyName
Parameters
Examples
The following example retrieves and displays the name of the company the
user is currently logged into.
Private Sub CompanyName_Click()
Dim UserInfoObj As UserInfo
Dim CompanyName As String
'Get the UserInfo object
Set UserInfoObj = VbaGlobal.UserInfoGet()
'Retrieve and display the company name
CompanyName = UserInfoObj.CompanyName
MsgBox CompanyName
End Sub
254
V B A
D E V E L O P E R S
G U I D E
R E A T E
A D O C
O N N E C T I O N
M E T H O D
CreateADOConnection method
Description
Syntax
UserInfo.CreateADOConnection()
Parameters
Examples
VBA
DEVELOPERS
GUIDE
255
N T E R C O M P A N Y
I D
P R O P E R T Y
IntercompanyID property
Description
Syntax
UserInfo.IntercompanyID
Parameters
Comments
The value of the IntercompanyID property is the same as the name of the
SQL database used for that company.
Examples
The following example retrieves and displays the intercompany ID for the
company the user is currently logged into.
Private Sub IntercompanyID_Click()
Dim UserInfoObj As UserInfo
Dim IntercompanyID As String
'Get the UserInfo object
Set UserInfoObj = VbaGlobal.UserInfoGet()
'Retrieve and display the intercompany ID
IntercompanyID = UserInfoObj.IntercompanyID
MsgBox IntercompanyID
End Sub
256
V B A
D E V E L O P E R S
G U I D E
S E R
A T E
P R O P E R T Y
UserDate property
Description
The UserDate property contains the user date currently set in Microsoft
Dynamics GP.
Syntax
UserInfo.UserDate
Parameters
Examples
VBA
DEVELOPERS
GUIDE
257
S E R
I D
P R O P E R T Y
UserID property
Description
The UserID property contains the user ID value for the user currently
logged into Microsoft Dynamics GP.
Syntax
UserInfo.UserID
Parameters
Comments
The value of the UserID property is the same as the users SQL login.
Examples
The following example retrieves and displays the user ID for the user
currently logged into Microsoft Dynamics GP.
Private Sub UserID_Click()
Dim UserInfoObj As UserInfo
Dim UserID As String
'Get the UserInfo object
Set UserInfoObj = VbaGlobal.UserInfoGet()
'Retrieve and display the user ID
UserID = UserInfoObj.UserID
MsgBox UserID
End Sub
258
V B A
D E V E L O P E R S
G U I D E
S E R
A M E
P R O P E R T Y
UserName property
Description
The UserName property contains the display name for the user currently
logged into Microsoft Dynamics GP.
Syntax
UserInfo.UserName
Parameters
Examples
VBA
DEVELOPERS
GUIDE
259
260
V B A
D E V E L O P E R S
G U I D E
APPENDIX
Appendix
This manual has the following appendix:
262
V B A
D E V E L O P E R S
G U I D E
Appendix A:
VBA Errors
The information presented here explains the runtime errors that you can
encounter using VBA with Microsoft Dynamics GP. It is divided into the
following sections:
VBA errors display a VBA dialog with an error number and message text.
VBA halts the execution of VBA code at the point the error occurred. You
can handle Microsoft Dynamics GP VBA errors in the same manner as other
errors that appear in VBA, using VBAs On Error statement to respond to
the error condition. The On Error statement has three clauses that allow
you to handle errors:
Statement
Description
On Error Go To line
On Error Go To 0
VBA
DEVELOPERS
GUIDE
263
A P P E N D I X
V B A
E R R O R S
Message text
1001
Unexpected error.
1002
1003
1004
1005
1006
1007
1008
80040208
To access online help for these VBA errors, press the Help button in the error dialog
when the error occurs.
264
V B A
D E V E L O P E R S
G U I D E
A PP E N D I X
Error 1001
V B A
E R R O R S
Unexpected error.
Situation:
This error occurs in the following instances:
You set the caption for a field that didnt previously have a caption.
Solution:
If youre using the Caption property to set a fields caption, be sure the
field has an existing caption.
If youre performing other tasks and receive this error, Microsoft Dynamics
GP may be running out of memory. Shut down applications that arent
necessary, then restart the accounting system. If the error persists, contact
Technical Support.
Error 1002
VBA
DEVELOPERS
GUIDE
265
A P P E N D I X
V B A
E R R O R S
Error 1003 Unsafe operation. This operation could compromise the integrity of
the application.
Situation:
You attempted to enable a field disabled by the accounting system, unlock a
field locked by the accounting system, make visible a field made invisible
by the accounting system, or make unrequired a field marked as required
by the accounting system. To preserve data integrity, Microsoft Dynamics
GP application code overrides any attempt you make through VBA to
change properties for disabled, locked, hidden or required fields.
Solution:
If Microsoft Dynamics GP application code disables, locks, hides or requires
a field, it may impact how your VBA code works with the field.
The following table explains some general guidelines for these properties:
266
V B A
D E V E L O P E R S
Property
Description
Enabled
Locked
If the accounting system locks a field, you cannot unlock it (set its
Locked property to False) or set its value using VBA.
Visible
If the accounting system hides a field, you cannot make the field
visible (set its Visible property to True) or set its value using VBA.
Required
If the accounting system requires a field, you cannot make the field
unrequired (set its Required property to False).
G U I D E
A PP E N D I X
Error 1004
V B A
E R R O R S
Property
Description
IsLoaded
Required
Parent
Object
DUOSObject
ID
DUOSObjects
Item
DUOSProperties
Item
Field
Error 1005 Unsafe operation. This operation can only be performed in the
BeforeGotFocus or AfterGotFocus events of the target field. The operation could
compromise the integrity of the application.
Situation:
You attempted to set the value of a composite field using the ValueSeg
method from an event other than the composite fields BeforeGotFocus or
AfterGotFocus events.
Solution:
When setting a composite field using the ValueSeg property, set the
composite from only the BeforeGotFocus or AfterGotFocus events for the
field. When a composite gains focus, Microsoft Dynamics GP application
code validates the value of the composite, segment by segment. Since the
accounting system can perform this validation only after segments values
have been set, you must set segment values using the ValueSeg property in
events that precede the validation (the BeforeGotFocus and AfterGotFocus
events).
VBA
DEVELOPERS
GUIDE
267
A P P E N D I X
V B A
E R R O R S
Error 1006 Unsafe operation. This operation cannot be performed in the target
fields AfterUserChanged, BeforeLostFocus or AfterLostFocus events. This
operation could compromise the integrity of the application.
Situation:
You attempted to set a fields value using the fields AfterUserChanged,
BeforeUserChanged or AfterLostFocus events. These events follow the
Microsoft Dynamics GP user changed event. Microsoft Dynamics GP uses
the user changed event to verify the value in a field; setting the value of the
field after the Microsoft Dynamics GP user changed event does not allow
the accounting system to verify the field.
Solution:
Set the fields value using the BeforeGotFocus, AfterGotFocus or
BeforeUserChanged events. These events precede the Microsoft Dynamics
GP user changed event, and allow the accounting system to verify the
contents of the field.
Error 1007 Unsafe operation. An attempt was made to set a value that violates
the applications business logic. This operation could compromise the integrity of
the application.
Situation:
You attempted to set a fields value from outside the field (before the field
gains focus), such as by using the windows BeforeOpen or AfterOpen
event, or another fields BeforeUserChanged or AfterUserChanged event.
When you set the value of a field before the field gains focus, VBA
automatically runs the Microsoft Dynamics GP user changed event for the
field youre setting. This is necessary so any accounting system application
code associated with these events can verify the fields value. Although
Microsoft Dynamics GP doesnt perform this verification for all fields, they
will perform verification for fields that affect business logic (such as an
invoice discount percent, or a tax amount) or for add-on-the-fly fields. If the
accounting system determines that the fields value is invalid, it will first
display its error dialog, followed by the VBA error dialog.
268
V B A
D E V E L O P E R S
G U I D E
A PP E N D I X
V B A
E R R O R S
Solution:
There are three ways to avoid this type of error:
Whenever possible, set a fields value from inside the field, after it
has gained focus, using the fields AfterGotFocus or BeforeGotFocus
field events. If your event procedure sets an invalid value, the accounting system will still display a dialog, but VBA wont generate the error:
Private Sub ShippingMethod_AfterGotFocus()
'Set the Shipping Method field to a value that doesn't exist.
ShippingMethod = "NEW"
End Sub
If you set the value from outside the field, before the field has gained
focus, use the Focus method with the setvalue parameter in your event
procedure. The Focus method moves the focus to the field, then sets it
to the value of the setvalue parameter:
Private Sub CustomerID_AfterUserChanged()
'Move the focus to the field, then set the value
ShippingMethod.Focus("NEW")
End Sub
Only set fields from outside the field if you know the accounting system isnt performing field verification. Microsoft Dynamics GP performs verification for fields that affect business logic (such as an invoice
discount percent, or a tax amount) or for add-on-the-fly fields. You can
set the value of add-on-the-fly fields only if the add-on-the-fly value
already exists as a record (such as an existing shipping method).
VBA
DEVELOPERS
GUIDE
269
A P P E N D I X
V B A
E R R O R S
Error 1008 Unsafe Operation. An attempt was made to set a value into an
application field that is disabled. This operation could compromise the integrity of
the application.
Situation:
You attempted to set the value of a field that was locked or disabled by the
accounting system.
Solution:
If Microsoft Dynamics GP application code disables or locks a field (the
fields Enabled property is False, or its Locked property is True), you
cannot set its value. The accounting system disables fields when they dont
apply in a given situation, and locks fields to preserve the integrity of
accounting data (such as document totals). However, you can set the value
of fields youve disabled or locked through VBA.
Error 80040208
events.
270
V B A
D E V E L O P E R S
G U I D E
Glossary
Additional headers and footers
Report bands that are printed when a
specified field changes.
Adds-allowed grid
A grid that allows the user to enter and
save new information using the grid.
Ask dialog
A modal dialog box that contains one or
more buttons, allowing the user to make
a selection, and displays message text.
Band
A section of a report, such as the body,
report header, report footer or a page
header.
Band events
A VBA event that occurs just before a
report band prints.
Browse-only grid
A grid that allows the user to browse
through items in the window, but not
make any changes.
Calculated field
A report field containing an expression
that combines fields in a reports table,
report fields, constants, functions and
operators. You can set or return the value
of user-defined calculated fields. You can
only return the value of Microsoft
Dynamics GP calculated fields.
Caption
A field caption is a text label that shows
the user the information thats displayed
or that can be entered in the
corresponding window field. A window
caption is the title of the window.
Editable grid
Composite field
A field made up of multiple segments.
Microsoft Dynamics GP account numbers
are composite fields.
Concatenate
To connect two or more strings to form a
single string.
Control field
A unique field in a window thats used to
control access to a record. In Microsoft
Dynamics GP, control fields are unique
values, such as document numbers or
customer IDs.
Currency field
A field that allows the user to enter a
currency amount.
Disabled field
A field that is unavailable to or cannot be
chosen by a user. A disabled button or
field appears dimmed.
DUOS
An acronym for Dynamic User Object
Store. The DUOS lets you use VBA to
create, store and retrieve user-definable
data objects.
Editable field
A field whose contents can be changed
by the user.
VBA
Event
An action for a given object where
associated application code (an event
procedure) runs.
Event procedure
VBA code that executes when a given
event occurs.
Field
A field contains a single piece of
information. A field can be displayed in a
window or on a report. The type of
information displayed depends on the
fields type.
Focus
The indicator that shows the object being
controlled in the current window.
Form
In applications like Microsoft Dynamics
GP, a group of windows that function
together for a common purpose.
Format
The extra characters, spacing and
attributes that can be applied to a field
when data is entered or displayed.
Forms dictionary
The dictionary that stores user-modified
resources for Microsoft Dynamics GP.
This dictionary is created when the
Modifier is accessed for the first time.
Getstring dialog
A modal dialog that contains a data entry
field and OK and Cancel buttons.
Grid
A window used to display information
from a table (also known as a scrolling
window). Grids allow the user to scroll
through records in the table. There are
three types of grids: browse-only,
editable and adds-allowed.
DEVELOPERS
GUIDE
271
GLOS SA RY
Grid event
Modifier
Group box
A box drawn around a group of check
boxes or other fields to visually group the
items.
Integer field
A field that allows the user to enter a
number between -32,768 and 32,767.
Keyable length
The number of characters that can be
typed in a field.
Layout window
A window in the Modifier and Report
Writer that allows users to design the
layout of a window, grid (scrolling
window) or report.
List field
Any list box, drop-down list, multi-select
list, button drop list, combo box or visual
switch field.
An action in VBA that you can perform
for a given object. Methods include
opening and closing a window or
moving a field in a window.
Modal dialog
Object model
The relationship objects have to each
other within a given application.
Package files
Special text files that are used to deliver
customizations made with the Modifier,
VBA, and the Report Writer.
Page footer
A report band placed at the bottom of
every report page. The page footer often
includes administrative information,
such as the name of the person running
the report.
Page header
A report band placed at the top of every
report page. The page header typically
includes fields for the page number, date
and time.
D E V E L O P E R S
Parameter
A value passed to or returned from a
VBA statement, function or procedure.
Pixel
V B A
Palette
Method
272
Procedure
A named sequence of statements
executed as a single unit. An event
procedure is the most common type of
procedure used in a VBA project.
G U I D E
Project file
A file containing VBA code, user forms
and objects. The project is named based
on the dictionary. For instance, the project
for Microsoft Dynamics GP is named
DYNAMICS.VBA.
For
third-party
applications
integrating
with
the
accounting system, this file is name.VBA,
where name is the name of the integrating
applications dictionary.
Prompt
See Caption.
Property
A characteristic of an object in VBA that
you can retrieve or set. Properties include
the title of a window, or the value of a
field.
Read only
A property access mode that indicates the
propertys value can only be returned.
Read/write
A property access mode that indicates the
propertys value can be returned or set.
Report event
A VBA event that occurs when you print
a report. Report events occur when the
report starts, just before a given band
within the report prints, and when the
report ends.
G L O S S A R Y
Report field
Any field that appears on a report. You
can use VBA to return the value of report
fields if theyre table fields, accounting
system calculated fields, or legends. You
can set the value of report fields only if
theyre user-defined calculated fields or
legend fields.
Report footer
A report band that prints at the bottom of
the last report page. Reports can include
report footers, page footers and
additional footers.
Report legend
A report field that contains data passed
to the report at runtime, before it prints.
Legend
fields
typically
include
information about the report, such as the
range of records the user chose for the
report.
Report Writer
A tool that allows you to modify reports,
or design new reports. A reports
dictionary stores these changes or
additions.
Required field
A field in which a value must be entered
to process information, such as an ID or
customer name. You can use VBA to
mark fields as required.
Required fields are displayed in a
different color or type style when a user
chooses the Show Required Fields menu
item.
Scrolling window
See Grid.
Segment
One portion of a composite field.
Microsoft Dynamics GP uses composite
fields for account numbers.
String field
A field that allows the user to enter up to
255 ASCII characters. VBA include any
formatting when setting or returning the
value of a string field.
Tab sequence
The order in which the focus moves from
one field to the next in a window when a
user presses the TAB key.
Text field
A field that allows the user to enter up to
32,000 ASCII characters. VBA references
the string value of a text field.
VBA
Visual Basic for Applications. A
development environment used to
interact with and control objects within
host applications.
Window
The work area used to enter and display
information in an application.
Window event
A VBA event that occurs when a window
opens, activates, closes or when a modal
dialog appears.
Window field
A field within a Microsoft Dynamics GP
window.
VBA
DEVELOPERS
GUIDE
273
274
V B A
D E V E L O P E R S
G U I D E
Index
A
account numbers
setting account segments 171
using 58
accumulator fields, in VBA 93
Activate method
described 122
using 27
activating windows 27
additional footer
defined 271
using the BeforeAF event 90
additional header
defined 271
using the BeforeAH event 89
adds-allowed grids
defined 271
described 78
ADO connection, creating for database
255
AfterActivate event
described 123
using 21
AfterClose event
described 124
using 21
AfterGotFocus event
avoiding errors 53
button drop list fields 55
described 158
using 37
AfterLineChange event
described 192
using 80
AfterLineGotFocus event
described 193
using 79
AfterLineLostFocus event
described 194
using 81
AfterLostFocus event
button drop list fields 55
described 159
related errors 268
B
band, defined 271
band events
defined 271
returning data from multiple
bands 94
suppressing report data 89
using 87
BeforeActivate event
described 129
using 21
BeforeAF event
described 210
using 90
BeforeAH event
described 211
using 89
BeforeBody event
described 212
using 90
VBA
BeforeClose event
described 130
using 20
BeforeGotFocus event
avoiding errors 53
button drop list fields 55
described 161
using 37
BeforeLineChange event
described 195
using 80
BeforeLineGotFocus event
described 196
using 79
BeforeLineLostFocus event
described 197
using 81
BeforeLinePopulate event
described 198
using 81
BeforeLostFocus event
button drop list fields 55
described 162
using 41
BeforeModalDialog event
described 131
using 22
BeforeOpen event
described 134
using 19
BeforePF event
described 213
using 90
BeforePH event
described 214
using 89
BeforeRF event
described 215
using 90
BeforeRH event
described 216
using 89
BeforeUserChanged event
button drop list fields 55
combo box fields 57
composite fields 58
described 163
DEVELOPERS
GUIDE
275
I N D E X
C
calculated fields
defined 271
referencing in reports 93
Cancel button, pushing from VBA 67
Cancel method
described 217
using with reports 91
canceling
field processing
got focus events 37
lost focus events 41
user changed events 39
grid processing 80
report processing 91
window processing 20
caption
applied to Microsoft Dynamics GP
fields 165
defined 271
Caption property
check box fields 56
described for fields 165
described for windows 135
push button fields 67
radio button fields 68
related errors 265
windows 28
276
V B A
D E V E L O P E R S
Changed event
button drop list fields 55
described for fields 166
push button fields 67
using 40
Changed property
described for grids 199
described for windows 136
check box field
defined 271
programming 56
circular references, avoiding 14
Clear button, pushing from VBA 67
Close method
described 137
using with windows 25
collections
creating a DUOS collection 100
DUOS object collection 12
DUOS property collection 12
combo box field
defined 271
programming 57
company ID, retrieving 256
company name, retrieving 254
CompanyName property, described for
UserInfo object 254
composite field
controlling the focus 44
defined 271
guidelines for setting 171
programming 58
related errors 267
concatenating, defined 271
connections, ADO connections to
database 255
constants
dcButton1, described 125, 131
dcButton2, described 125, 131
dcButton3, described 125, 131
dcCancel, described 125, 131
dcOK, described 125, 131
dtModalAskDialog, described 125,
131
dtModalGetStringDialog,
described 125, 131
emModifiedOnly, described 138
G U I D E
constants (continued)
emNever, described 138
emOriginalOnly, described 138
control field
defined 271
using to retrieve a DUOS data
object 106
conventions in documentation 3
converting fields
for numeric calculations 49
guidelines for field values 50
using VBAs conversion functions
50
Count property, described 244
CreateADOConnection method,
described for UserInfo object 255
currency field
defined 271
programming 60
Customization Maintenance window
115
Customization Site Enabler, described
113
D
data objects
creating 100
deleting 101, 107
described 97
printing 110
retrieving 101, 106
saving 104
storage with Microsoft Dynamics
GP 99
updating 101
database
creating ADO connection to 255
names of in Microsoft Dynamics
GP 256
date, retrieving user date 257
date field, programming 61
Delete button, pushing from VBA 67
deleting
DUOS data objects 107
modified forms, impact on VBA 19
disabled fields
defined 271
I N D E X
E
editable fields, defined 271
editable grids
defined 271
described 78
Empty property
described 168
using 48
Enabled property
described 169
related errors 266, 270
using 43
End event
described 218
using 87
errors
appendix 263-270
error 1001 265
error 1002 265
error 1003 266
error 1004 267
error 1005 267
error 1006 268
error 1007 268
error 1008 270
error 80040208 270
handling VBA errors 263
VBA error list 264
when setting fields 52
event procedures
see also events
defined 271
EventMode property
described for grids 200
described for reports 219
described for windows 138
using with grids 82
using with reports 85
using with windows 29
events
defined 271
described 13
events (continued)
for grids 78
for reports 85
for window fields 35
for windows 18
Exists property, described 232, 245
expand button, pushing from VBA 67,
71
exporting data to other applications 95
exporting package files 115
extender properties, described 178
external components, referencing 113
F
field object library 157-189
fields
see also window fields
defined 271
grid fields 75
report fields 92
window fields 47
working with report fields 88
working with report legends 86
focus, defined 271
Focus method
avoiding errors 53
described 170
using 44
FocusSeg method
composite fields 58
described 171
using 44
Format function, use with report fields
93
formats
composite format 58
currency format 60
date format 61
defined 271
integer format 63
report field format 93
string format 69
forms
defined 271
using with VBA 26
forms dictionary, defined 271
VBA
DEVELOPERS
GUIDE
277
I N D E X
G
getstring dialogs
defined 271
responding to 127
got focus events, using 36
grid events
defined 272
line change events 79
line got focus events 79
line lost focus events 81
line populate events 81
grid object library 191-208
grids
see also grid events
adding to a project 75
adding window fields from 75
canceling processing 80
changing a grids name 82
chapter 73-82
defined 271
filtering grid content 81
in the object model 10, 11
programming 73, 76
property and method list 82
removing from a project 75
types of 77
using grid events 78
using VBA with modified grids 79
group box, defined 272
H
Height property
described for fields 173
described for windows 140
using 28
Hide method
described for grids 201
described for windows 141
using 27
hiding
report fields 93
window fields 45
windows 27
I
ID property, described 240
IDs, retrieving user ID 258
278
V B A
D E V E L O P E R S
K
keyable length, defined 272
L
layout windows, defined 272
Left property
described for fields 174
described for grids 202
described for windows 143
using 28
Legend property
described 220
using with reports 92
light bulb symbol 3
line change events, using 79
line got focus events, using 79
line lost focus events, using 81
line populate events, using 81
list box field
defined 272
programming 64
list fields
button drop list 55
defined 272
drop-down list 62
list box 64
multi-select list box 65
Locked property
described 175
related errors 266, 270
using 43
locking window fields 43
lookup button, pushing from VBA 67
lost focus events, using 41
G U I D E
M
margin notes 3
messages, see modal dialogs
method list
DUOS 102
grids 82
reports 91
window fields 43
windows 24
methods
defined 272
described 12
Microsoft Office, exporting data to
Office applications 95
Missing File dialog 113
modal dialog events
defined 272
using 22
modal dialogs
changing the contents of 23
defined 272
delete dialog and the DUOS 107
programmatically answering 22
responding to 22
save dialog and the DUOS 105
types 126
using with the DUOS 23
Modifier
defined 272
using VBA with grids 79
using VBA with modified
windows 19
using with VBA 13
Move method
described for fields 176
described for grids 203
described for windows 144
moving windows 28
multi-select list box field
defined 272
programming 65
N
Name property
described for a DUOSObjects
collection 234
I N D E X
O
object model
defined 272
using the object model 10
Object property, described 178
objects
DUOS data object 12
DUOS property object 12
field object, described 11
grid object, described 11
in the object model 10
report object, described 11
user information object, described
11
using with events 13
using with methods 12
using with properties 12
window field object, described 32
window object, described 11, 16
Open method
described 146
using with windows 25
opening windows, guidelines 146
overwriting customizations with
package files 118
P
package files
contents 115
defined 272
VBA
project (continued)
renaming grids 82
renaming window fields 46
renaming windows 29
Project Explorer
described 8
viewing grids 75
viewing reports 83
viewing window fields 32
viewing windows 16
project file
defined 272
described 8
for third-party applications 8
prompt, see caption
properties
custom, described 178
defined 272
described 12
related errors 267
standard, described 178
Properties property, described 241
property list
DUOS 102
grids 82
reports 91
window fields 43
windows 24
PullFocus method
described 148
related errors 270
push button field
defined 272
programming 67
R
radio button field
defined 272
programming 68
radio button group 68
read only, defined 272
read/write, defined 272
references
to external components 113
to third-party dictionaries 14
registration keys, for VBA 113
DEVELOPERS
GUIDE
279
I N D E X
Remove method
described for a DUOSObject
collection 235
described for DUOSProperties
collection 248
report body, using the BeforeBody
event 90
report events
band events 87
defined 272
Start/End events 86
report fields
accumulator fields 93
adding to a project 84
calculated fields 93
defined 273
format of returned values 93
guidelines for use 92
hiding and showing 93
in the object model 10
legend fields 86
returning 88
setting 88
suppressing 89
table fields 92
report footer
defined 273
using the BeforeRF event 90
report header, using the BeforeRH
event 89
report legends
defined 273
setting from a Start event 86
report object library 209-222
report sections, see band events
Report Writer
defined 273
using VBA with modified reports
85
reports
see also report events
adding to a project 83
canceling 91
chapter 83-96
exporting data to other
applications 95
in the object model 10, 11
280
V B A
D E V E L O P E R S
reports (continued)
programming 83
property and method list 91
removing a report 84
returning data from an entire
report 94
returning report fields 88
setting report fields 88
using legend fields 86
using report events 85
using VBA with modified reports
85
required fields
defined 273
using the Required property 46
Required property
described for fields 181
described for windows 150
related errors 266
using with the DUOS 104
using with window fields 46
resizing windows 28
Resource Descriptions tool
defined 273
described 54
retrieving DUOS data objects 106
returning report fields
from a Start event 86
from band events 88
returning window fields, guidelines 48
runtime errors, see errors
S
Save button
pushing from VBA 67
using with the DUOS 104
saving DUOS data objects 104
scrolling windows
see also grids
pushing expand and shrink
buttons 71
security, setting access to customized
resources 117
segments
controlling the focus within a
composite 44
defined 273
G U I D E
segments (continued)
guidelines for setting 171
using with a composite 58
setting report fields
using a Start event 86
using band events 88
setting window fields
guidelines 50
related errors 268
using a BeforeGotFocus event 37
using a BeforeUserChanged event
39
using an AfterGotFocus event 37
Show method
described for grids 206
described for windows 151
showing
report fields 93
window fields 45
windows 27
shrink button, pushing from VBA 71
SortByExisting property, described 236
Start event
described 222
using 86
stick pin button, pushing from VBA 71
storing additional data, chapter 97-111
string field
defined 273
programming 69
support available for VBA 3
SY_User_Object_Store table, described
99
symbols in documentation 3
T
tab sequence, defined 273
table fields, for reports, using with
VBA 92
TabStop property, described 182
technical support for VBA 3
text field
defined 273
programming 70
third-party dictionaries
project file 8
using VBA with 14
I N D E X
U
user changed events, using 38
user information, in the object model
11
UserDate property, described for
UserInfo object 257
UserID property, described for
UserInfo object 258
UserInfo object library 253-259
UserInfoGet method, described 230
UserName property, described for
UserInfo object 259
Using VBA, part 6-118
V
Value property
button drop list fields 55
check box fields 56
combo box fields 57
composite fields 58
currency fields 60
date fields 61
described for a DUOSProperty
object 251
described for fields 184
drop-down list fields 62
guidelines for returning window
fields 48
guidelines for setting fields 50
integer fields 63
list box fields 64
multi-select list box fields 65
push button fields 67
radio button fields 68
related errors 268
string fields 69
text fields 70
using with report fields 88
using with window fields 47
visual switch fields 71
ValueSeg property
composite fields 58
described 187
related errors 267
using 47
using with the FocusSeg method
171
VBA
creating the project file 8
defined 273
described 2
documentation 2
enabling 113
packaging a project 114, 115
prerequisites 2
registration keys 4, 113
using with fields 34
using with grids 76
using with reports 83
using with the Dynamic User
Object Store (DUOS) 97
using with the Modifier 13
using with windows 17
Visual Basic Editor 7
VBA Object Library, part 120-259
VBA Overview, chapter 7-14
VBAGlobal object library 223-230
Visible property
described for fields 188
described for grids 208
described for windows 153
related errors 266
using with report fields 93
using with window fields 45
using with windows 27
Visual Basic Editor, described 7
Visual Basic for Applications, see VBA
visual switch field
defined 273
programming 71
W
warning messages, see modal dialogs
warning symbol 3
Width property
described for fields 189
described for windows 155
VBA
DEVELOPERS
GUIDE
281
I N D E X
282
V B A
D E V E L O P E R S
windows (continued)
in the object model 10, 11
moving and resizing 28
opening and closing 25
opening invisibly 19
programming 15, 17
property and method list 24
removing window objects 17
renaming windows 29
setting the event mode 29, 82
using VBA with modified
windows 19
using window events 18
G U I D E