BusinessObjects Board

Change Source Universe for Multiple Documents

Original Author: Jean-Francois Cayron
Author Notes:

Change Universe

Sub ChangeUniverse()
Dim UnvCount As Integer
Dim UnvNameList() As String
Dim ix As Integer
Dim DefaultPath As String
DefaultPath = "C:\infosol\"
Application.Interactive = False
Set CurDoc = Application.ActiveDocument
Set UnvList = Application.Universes
UnvCount = UnvList.Count
ReDim UnvNameList(UnvCount)
For ix = 1 To UnvCount
    UnvNameList(ix) = UnvList.Item(ix).LongName
    frmChoose.cboxFrom.AddItem (UnvNameList(ix))
    frmChoose.cboxTo.AddItem (UnvNameList(ix))
Next ix
frmChoose.txtPath.Value = DefaultPath
Application.Interactive = True
frmChoose.cboxFrom.ListIndex = 0
frmChoose.cboxTo.ListIndex = 0
frmChoose.Show

End Sub

Private Sub btnCancel_Click()
Unload Me
End Sub

Private Sub btnGo_Click()
Dim ix, iy As Integer
Dim CountDP As Integer
Dim CountDocs As Integer
Dim ChangeFrom As String
Dim ChangeTo As Universe
Dim Docs As Documents
Dim CurDoc As Document
Dim DPList As DataProviders
Dim CurDP As DataProvider
Dim CurUnvName As String
Dim FolderName As String
Dim SearchPath As String
Dim DocName As String
Dim DocList() As String
Dim DocCount As Integer
Dim DirtyDoc As Boolean
Dim ErrorOn As Boolean
Dim ErrDocs() As String
Dim ErrCount As Integer
Dim ErrDisplay As String
Set Docs = Application.Documents
FolderName = Me.txtPath
On Error GoTo WrongPath
ChDir (FolderName)
If Mid(FolderName, 2, 1) = ":" Then ChDrive (FolderName)
On Error GoTo 0
FolderName = CurDir() & "\"
SearchPath = FolderName & "*.rep"
ChangeFrom = Me.cboxFrom.Value
Set ChangeTo = UnvList.Item(Me.cboxTo.ListIndex + 1)
DocName = Dir(SearchPath) 'Get first document and loop through the list
ix = 1
Do While DocName <> ""
    ReDim Preserve DocList(ix)
    DocList(ix) = DocName
    DocName = Dir() '    Get next document
    ix = ix + 1
Loop
DocCount = ix - 1
CountDP = 0
CountDocs = 0
ErrCount = 0
Application.Interactive = False
For iy = 1 To DocCount
    DirtyDoc = False  ' True means save document
    DocName = FolderName &amp; DocList(iy) ' Give full path, or it will try to open it in UserDocs
    Set CurDoc = Docs.Open(DocName, True) ' Open with NoRefresh (true)
    Set DPList = CurDoc.DataProviders
    For ix = 1 To DPList.Count  ' For each data provider
        Set CurDP = DPList.Item(ix)
        CurUnvName = CurDP.UniverseName
        If CurUnvName = ChangeFrom Then '  If it was the universe we are looking for...
            CountDP = CountDP + 1
            DirtyDoc = True
            On Error GoTo ChgUnvError
            CurDP.ChangeUniverse ChangeTo ' Change it to the new one
            On Error GoTo RefreshError
            CurDP.Refresh   ' ..........    And Refresh the DP
            On Error GoTo 0
        End If
    Next ix
    If DirtyDoc Then
        CountDocs = CountDocs + 1
        CurDoc.Save
    End If
    CurDoc.Close
Next iy
Application.Interactive = True
MsgBox "Modified  " &amp; CountDP &amp; " data providers in " &amp; CountDocs &amp; " documents"
If ErrCount > 0 Then
    ErrDisplay = "Errors occured :" &amp; Chr$(13)
    For ix = 1 To ErrCount
        ErrDisplay = ErrDisplay &amp; ErrDocs(ix) &amp; Chr$(13)
    Next
    MsgBox ErrDisplay
End If
Unload Me
Exit Sub

RefreshError:
    ErrCount = ErrCount + 1
    ReDim Preserve ErrDocs(ErrCount)
    ErrDocs(ErrCount) = "Could not refresh " &amp; CurDoc.Name
    MsgBox "refresh error"
    Resume Next

ChgUnvError:
    Application.Interactive = True
    MsgBox "Problem changing the universe on DP " &amp; CurDP.Name &amp; " of document " &amp; CurDoc.Name
    Unload Me
 Exit Sub

WrongPath:
    Application.Interactive = True
    MsgBox "Check the path."
    Exit Sub
End Sub

Note: This code is not functional by itself. You should download the add-in (rea file) in order to get the form that is called.
ChangeUniverse.zip (25.0 KB)


BOB Downloads (BOB member since 2003-05-05)

Hi,

beside other downloads, this looks like a very useful functionality. Is there a version working with BOXI R2 SP2?

Kind regards


fornofm :de: (BOB member since 2004-08-23)

Hi,

does this apply to webi document ? or only rep files, as stated in the code ??

Thanks

Luc


luc_chivas (BOB member since 2008-10-16)

Doesn’t work anyway, produces an error 5 ‘invalid object’ when enumerating the universes


fdu (BOB member since 2010-11-22)

Only rep files.


Marek Chladny :slovakia: (BOB member since 2003-11-27)

It’s 8-years old code developed in an outdated BO version (probably BO 5.x). So it’s normal that when you are trying to run it for instance in BO XI 3 then you could get an error.


Marek Chladny :slovakia: (BOB member since 2003-11-27)

Does anyone know of a 3.1 version of this type of tool? Something under 10k/yr would be preferred.

-Mark


MarkIngle (BOB member since 2007-05-31)

Hi All,

I have modified utiltiy posted by Jean-Francois Cayron, post URL: Change Source Universe for Multiple Documents

I have modifed and tested it for 3.0 and 3.1 all service pack. I added login form inorder to avoid hard coded authentication details. Also modified interface and removed errors which i received to work this utilty better and much faster.

I hope this helps everone.

Thanks,
Sunder
ChangeUniverse.zip (56.0 KB)


sunder.ramani (BOB member since 2009-05-27)

Mark,
It is possible to develop such an application using Java & BO/RE SDK. Please contact me by email.

Thanks


xguru (BOB member since 2011-04-09)

The point of a bulletin board is the sharing of information. As such we really prefer it if you can share your ideas in public. Thanks for understanding :mrgreen:


Nick Daniels :uk: (BOB member since 2002-08-15)