BusinessObjects Board

Mass update scheduled instances with VBA

Is there a way to do mass update of scheduled Crystal Reports with VBA? We have a large number of instances whose database account and password need to be updated.

the pseudo code I used is as follows:

Dim Instances As InfoObjects
Dim Instance As InfoObject

Dim newSchedRpt As Report
Dim RptLogons As ReportLogons
Dim RptLogon As ReportLogon

For Each Instance In Instances

   Set newSchedRpt = Instance
   Set RptLogons = newSchedRpt.ReportLogons
   For Each RptLogon In RptLogons
       RptLogon.userName = frmInstance.tbNewUser
       RptLogon.Password = frmInstance.tbNewPassword
   Next RptLogon

Next Instance

This VBA code worked if the format of the instance is “Default”. If it’s Excel or PDF then I got the “Type mismatch” error message on this command line “Set newSchedRpt = Instance”

Has anyone come across this before?


boausdev (BOB member since 2008-08-04)

The problem is that non-default scheduled instances have an SI_KIND value matching the file type (Pdf or Excel) rather than the source document type (Report, Webi, etc.), and this translates to the subtype of InfoObject that is created. So in your program you’re actually trying to cast Instance, which is an object of type “Pdf” to “Report”. (In real languages, this would produce a class cast exception).

It works for instances that are “Default” because the object type is actually Report.

What you need to do is cast the InfoObject to the appropriate subtype, then call PluginInterface(“Report”) to get a handle to the ReportProcessingInfo object that you need. Here’s a sketch:

    For Each instance In ioinstances
        If instance.Kind = "Pdf" Then
            Set pdf = instance
            Set RptLogons = pdf.PluginInterface("Report").reportlogons
            For Each RptLogon In RptLogons
                RptLogon.UserName = frmInstance.tbNewUser
                RptLogon.Password = frmInstance.tbNewPassword
            Next RptLogon
        End If
    Next instance

Note that this only handles Pdf types. You’d have to add code to handle other static types as well.

Joe


joepeters :us: (BOB member since 2002-08-29)

Interesting Joe, I had an idea of what the issue was, but didn’t know the code to solve it.

Thanks for the great explanation 8)


Mak 1 :uk: (BOB member since 2005-01-06)

My pleasure :slight_smile:

I actually first thought it wasn’t possible in VBA, but then found the PluginInterface method. I wish the SDK was better documented.

Java solution here.


joepeters :us: (BOB member since 2002-08-29)

That makes sense, thanks for the explanation, Joe! :smiley:


boausdev (BOB member since 2008-08-04)

is there a way to update the database credential for scheduled Notification?


boausdev (BOB member since 2008-08-04)