Biographical fields are blanked out when using VBA macro with SessionContext

When using a VBA macro with SessionContext and all solicit codes added to a constituent record, all the biographical information of the underlying record is cleared out and hence cannot be saved. 
The following line of code will initialize a blank constituent, which is why the BIO form fields become blank.

oConstit.Init REApplication.SessionContext

Note: Initializing a constituent record after it has already been set to an object will be subject to behavior that isn't necessarily consistent with what somebody might expect.  That isn't to say that it will never work, but we can't guarantee that the results will work in every scenario.

If there is a question about whether or not oRec has been initialized I would add a check to see if oRec is Nothing before trying to do anything with it.  If it is nothing then you can initialize it, but if it is already an object then you don't want to run the risk of messing with the integrity of the object as you re-initialize the object that already has data.

Steps to Duplicate

Please place the code below in the ‘System_Macros’ module, save it and then perform the following steps:
  • Open any constituent record
  • Click on the Solicit code hyperlink to open the selection window on the lower left of BIO1 tab
  • Add all the solicit codes to the constituent
  • Click OK
  • Run the macro from the Run Macro button on the upper toolbar of the constituent form
Once the message box has closed you should see that the Biographical data has all been cleared. If you comment out the ‘oConstit.Init REApplication.SessionContext’ line, the code runs fine and the constituent data remains unaffected. The simple macro code is below.

Public Sub Test_SessionContext(oRec As IBBDataObject) 'Test Function    
If TypeOf oRec Is CRecord Then
       Dim oConstit As CRecord
       Set oConstit = oRec
       oConstit.Init REApplication.SessionContext
       If oConstit.SolicitCodes.Count > 0 Then
            MsgBox "This Constituent has Solicit Codes", vbOKOnly, "Message"
        Else
           MsgBox "This Constituent has no Solicit Codes", vbOKOnly, "Error"
      End If
      Set oConstit = Nothing
Else
      MsgBox "This macro must be fired from a constituent record"
End If 'End of Test Function
End Sub

Environment

 Raiser's Edge
 7.96

Was this article helpful?


Thanks for your feedback! Did this solve your issue?

Comments (optional):


Thanks for your feedback!
We're glad it was helpful but sorry it didn’t solve your issue. If you need assistance, click Chat with Support below.
We’re sorry to hear that. Please tell us why.

 I don't like how this works.

 The answer is confusing.

 The answer didn't match what I was searching for.

Additional Comments (optional):


Thanks for your feedback! If you need assistance, click Chat with Support below.
Thanks for your feedback. Help us make our products even better by sharing details in our Idea Banks or our online Community.
Thanks for letting us know. We'll work on clarifying the information in the article. If you need assistance, click Chat with Support below.
Thanks for letting us know. We'll work on updating the search engine to return more relevant results.