GetNextReceipt Method, Step5 (Visual Basic)
Public Function GetNextReceipt() As Long
On Error GoTo ErrorHandler
' If Shared property does not already exist
' it will be initialized
Dim spmMgr As SharedPropertyGroupManager
Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
Dim spmGroup As SharedPropertyGroup
Dim bResult As Boolean
Set spmGroup = _
spmMgr.CreatePropertyGroup("Receipt", _
LockMethod, Process, bResult)
Dim spmPropNextReceipt As SharedProperty
Set spmPropNextReceipt = _
spmGroup.CreateProperty("Next", bResult)
' Set the initial value of the Shared Property to
' 0 if the Shared Property didn’t already exist.
' This is not entirely necessary but demonstrates
' how to initialize a value.
If bResult = False Then
spmPropNextReceipt.Value = 0
End If
' Get the next receipt number and update property
spmPropNextReceipt.Value = spmPropNextReceipt.Value + 1
' we are finished and happy
GetObjectContext.SetComplete
GetNextReceipt = spmPropNextReceipt.Value
Exit Function
ErrorHandler:
GetObjectContext.SetAbort ' we are unhappy
' indicate that an error occured
GetNextReceipt = -1
Err.Raise Err.Number, _
"Bank.GetReceipt.GetNextReceipt", _
Err.Description
End Function