A composite field displays information from multiple fields called segments. Microsoft Dynamics GP primarily uses composite fields for account numbers.
The BeforeUserChanged and AfterUserChanged events occur for the composite field when the user changes information in any segment, then moves the focus out of the composite. No events occur when the user changes the value of a segment, then moves to another segment in the same composite. All other VBA field events occur when you move the focus into or out of the composite.
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.
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
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