Veja a função que abre o relatorio
Private Function F_Visualizar(FilDados As TpUniFil, LocRel As String, RelName As String, SqlWhere As String, AbrirForm As Boolean, Optional Imprimir As Boolean = False, Optional PedirImpressora As Boolean = False)
On Error GoTo TE_Vis
Const ErrFunc As String = "F_Visualizar"
Dim ObjCRV As CRViewer
Set ObjCRV = FrmUniRel.CR
'Abre o Relatório
Screen.MousePointer = 11
Set CR_Relatorio = CR_Aplicacao.OpenReport(LocRel, 1)
'Loga as Tabelas no Banco de Dados c/ Senha
For Each CR_DatabaseTable In CR_Relatorio.DataBase.Tables
CR_DatabaseTable.SetLogOnInfo "Servidor", "AutoSystem2005", "Todos", "123"
CR_DatabaseTable.TestConnectivity
Next CR_DatabaseTable
'SubReport
ZeraVar01 = "Sub" 'Verifica se Existe erro
Dim ContSubRel As Integer
ContSubRel = 1
Do While ZeraVar01 <> "Erro"
'Abrir SubRelatório
Set CR_SubRelatorio(ContSubRel) = CR_Relatorio.OpenSubreport(Mid(RelName, 1, Len(RelName) - 4) & "Sub" & ContSubRel)
If ZeraVar01 = "Erro" Then Exit Do
'Loga as Tabelas do SubReport - Se Existir
For Each CR_DatabaseTable In CR_SubRelatorio(ContSubRel).DataBase.Tables
CR_DatabaseTable.SetLogOnInfo "Servidor", "AutoSystem20005", "Todos", "123"
CR_DatabaseTable.TestConnectivity
Next CR_DatabaseTable
ContSubRel = ContSubRel + 1
Loop
'Fixa Relatório na Váriavel Database
Set CR_Database = CR_Relatorio.DataBase
'Seleciona Registros
CR_Relatorio.RecordSelectionFormula = SqlWhere
'Formula Field
Dim ContFil As Integer
ContFil = 1
ZeraVar01 = ""
Do While ZeraVar01 <> "Erro"
Set CR_FormulaFieldNome(ContFil) = CR_Relatorio.FormulaFields.GetItemByName("FilNome" & Format(ContFil, "00"))
If ZeraVar01 = "Erro" Then Exit Do
CR_FormulaFieldNome(ContFil).Text = "'" & FilDados.Nome(ContFil) & "'"
ZeraVar01 = ""
Set CR_FormulaFieldDesc(ContFil) = CR_Relatorio.FormulaFields.GetItemByName("FilDesc" & Format(ContFil, "00"))
If ZeraVar01 = "Erro" Then Exit Do
CR_FormulaFieldDesc(ContFil).Text = "'" & FilDados.Desc(ContFil) & "'"
ContFil = ContFil + 1
Loop
If PedirImpressora = True Then CR_Relatorio.PrinterSetup (0)
If Imprimir = True Then
CR_Relatorio.PrintOut (False)
Screen.MousePointer = 1
Exit Function
End If
'Abre e Mostra Relatório
ObjCRV.ReportSource = CR_Relatorio
Screen.MousePointer = 1
If AbrirForm = True Then If Screen.ActiveForm.Name <> FrmUniRel.Name Then FrmUniRel.Show vbModal
Exit Function
TE_Vis:
If Err.Number = -2147190528 Or Err.Number = -2147189582 Then
ZeraVar01 = "Erro"
Resume Next
End If
Select Case F_Error(ErrForm, ErrFunc)
Case 0
Resume
Case 1
Resume Next
Case 2
Exit Function
End Select
End Function