Public Sub GetEventfromGift()

Dim oGift As CGift
Dim oGiftParticipant As CGiftParticipant
Dim oParticipant As CParticipant
Dim oEvent As CSpecialEvent
Dim bFundError As Boolean
Dim sGiftFund As String

'set and load gift to find event
Set oGift = New CGift
oGift.Init REApplication.SessionContext
oGift.Load 1463

'Check to see if the gift is linked to an event
If oGift.ParticipantLinker.IsLinked = True Then
'loop through all participations the gift is linked to
Select Case oGift.ParticipantLinker.LinkType
Case 1 'Linked to event as registration
For Each oGiftParticipant In oGift.ParticipantLinker.ParticipantRegFees
'set and load participation record
Set oParticipant = New CParticipant
oParticipant.Init REApplication.SessionContext
oParticipant.Load oGiftParticipant.Fields(GIFTPARTICIPANT_fld_ParticipantId)

'get the event record based on participation record
Set oEvent = oParticipant.EventObject
MsgBox "Gift is linked to the " & oEvent.Fields(SPECIAL_EVENT_fld_NAME) & " event."

'close down objects
oEvent.CloseDown
Set oEvent = Nothing
oParticipant.CloseDown
Set oParticipant = Nothing
Next oGiftParticipant
Set oGiftParticipant = Nothing
Case 2 'Linked as a donation for an event
Set oParticipant = New CParticipant
oParticipant.Init REApplication.SessionContext
oParticipant.Load oGift.ParticipantLinker.ParticipantId

'get the event record based on participation record
Set oEvent = oParticipant.EventObject
MsgBox "Gift is linked to the " & oEvent.Fields(SPECIAL_EVENT_fld_NAME) & " event."

'close down objects
oEvent.CloseDown
Set oEvent = Nothing
oParticipant.CloseDown
Set oParticipant = Nothing
Case 3 'Sponsoring Pledge for an event
Set oParticipant = New CParticipant
oParticipant.Init REApplication.SessionContext
oParticipant.Load oGift.ParticipantLinker.ParticipantId

'get the event record based on participation record
Set oEvent = oParticipant.EventObject
MsgBox "Gift is linked to the " & oEvent.Fields(SPECIAL_EVENT_fld_NAME) & " event."

'close down objects
oEvent.CloseDown
Set oEvent = Nothing
oParticipant.CloseDown
Set oParticipant = Nothing
End Select
End If

oGift.CloseDown
Set oGift = Nothing

End Sub

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.