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”
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.