ayuda con crystal report
soy nuevo en esto del crystal report, estoy usando el control CRViewer y no se como indicarle el informe que quiero imprimir.
gracias
gracias
entra en proyecto, componentes y dale click en examinar
busca el archivo crystl32.ocx, se encuentra en la carpeta del cristal report /windows/system32
y agregalo
te aparecera un componente que se llama crystal report control
has un boton de comando y agrega el sig. codigo
crystalreport1.reportfilename="ruta del reporte"
crystalreport1.action=1 'Para que salga el reporte
busca el archivo crystl32.ocx, se encuentra en la carpeta del cristal report /windows/system32
y agregalo
te aparecera un componente que se llama crystal report control
has un boton de comando y agrega el sig. codigo
crystalreport1.reportfilename="ruta del reporte"
crystalreport1.action=1 'Para que salga el reporte
La forma sería la siguiente:
'Declaramos los objetos
Dim RepApp As New CRAXDRT.Application
Dim repRep As CRAXDRT.Report
'Asignamos el report
Set repRep = RepApp.OpenReport(Path del report)
'Asignamos al visor el objeto report
CRViewer.ReportSource = repRep
'Lo visualizamos
CRViewer.Viewreport
Tienes que pensar que con RDC (Report Design Component) tienes 3 componentes independientes para trabajar con informes de Crystal Reports.
1) Visor de informes -> CRViewer
2) Automation Server ->El modelo de objetos CRAXDRT
3) Diseñador embebido de Informes
Lo basico es utilizar los dos primeros, como el ejemplo que te he pasado.
Automation server para la declaración del objeto report y su actuación sobre el, y el visor, que te deja libertad para modificar su comportamiento y estetica (entre otras cosas).
Un saludo
'Declaramos los objetos
Dim RepApp As New CRAXDRT.Application
Dim repRep As CRAXDRT.Report
'Asignamos el report
Set repRep = RepApp.OpenReport(Path del report)
'Asignamos al visor el objeto report
CRViewer.ReportSource = repRep
'Lo visualizamos
CRViewer.Viewreport
Tienes que pensar que con RDC (Report Design Component) tienes 3 componentes independientes para trabajar con informes de Crystal Reports.
1) Visor de informes -> CRViewer
2) Automation Server ->El modelo de objetos CRAXDRT
3) Diseñador embebido de Informes
Lo basico es utilizar los dos primeros, como el ejemplo que te he pasado.
Automation server para la declaración del objeto report y su actuación sobre el, y el visor, que te deja libertad para modificar su comportamiento y estetica (entre otras cosas).
Un saludo
Yosy me parece muy interesante la informacion que le diste a bera para lanzar un Report. Yo lo intente y no me funciona. Me podrias indicar tu u otro colega del foro, que componentes o referencias tengo que incluir en mi proyecto para que me reconozca el CRAXDRT. Me podrias decir tambien donde puedo encontrar documentacion sobre CRViewer ya que me imagino que este sera para seleccionar registros, Ordenar, Agrupar. Muchas, muchas gracias...
yosy . . . .
antes que nada recibe un gran saludo, el problema que tengo es que necesito enviar a imprimir 5 reportes distintos pero sin pasar por un vista previa desde un aplicacion de VB, esto es posible???, bueno si existe alguien que me pueda saludar se los agradeceria
antes que nada recibe un gran saludo, el problema que tengo es que necesito enviar a imprimir 5 reportes distintos pero sin pasar por un vista previa desde un aplicacion de VB, esto es posible???, bueno si existe alguien que me pueda saludar se los agradeceria
Otra forma es creando un modulo y un form con el ocx de crystal y escribir esto en el modulo para poder ejecutar el reporte desde cualquier formulario que necesites usar el reporte.
Escribir este código en el modulo
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim CONN_REP As ADODB.Connection
Public Enum VistaReport
LJVentana = 0
LJImpresora = 1
LJArchivo = 2
End Enum
Public Sub REP(ByVal NOMBRE_DEL_REPORTE, ByVal TITULO, ByVal Filtro As String, Vista As VistaReport)
On Error GoTo RutErrImp
Dim RPT As Object
Dim CurrenthWnd As Long
Dim sWindowTitle As String
Dim AccessConnect As String
Dim liNumSubrep, liIdx As Integer
Set RPT = CreateObject("Crystal.CrystalReport")
With RPT
.ReportFileName = App.Path & "Reportes" & NOMBRE_DEL_REPORTE & ".rpt"
If Filtro <> "" Then
.SelectionFormula = Trim$(Filtro)
Debug.Print "Filtro reporte " & NOMBRE_DEL_REPORTE & " = " & Filtro
End If
sWindowTitle = TITULO
.DiscardSavedData = True
.WindowState = crptMaximized
.WindowTitle = sWindowTitle
.WindowShowProgressCtls = True
.WindowShowZoomCtl = True
.WindowShowRefreshBtn = True
.WindowShowPrintSetupBtn = True
.WindowMinButton = True
.WindowShowCancelBtn = True
.WindowShowExportBtn = True
.WindowMaxButton = True
.WindowState = crptMaximized
.WindowShowSearchBtn = True
.WindowShowGroupTree = True
.WindowAllowDrillDown = True
.Destination = Vista
.Connect = Conn
Screen.MousePointer = 11
Sleep 5000
Screen.MousePointer = 0
.PrintReport
If .LastErrorNumber > 0 Then
If .LastErrorNumber = 20507 Then
MsgBox .LastErrorNumber & ", " & .LastErrorString & " = " & NOMBRE_DEL_REPORTE, vbCritical, "GENERANDO EL REPORTE" & "- Error en el reporte -"
ElseIf .LastErrorNumber = 20510 Then
ElseIf .LastErrorNumber = 20515 Then
MsgBox Filtro & ", " & .LastErrorString
Else
MsgBox .LastErrorNumber & ", " & .LastErrorString, vbCritical, TITULO & "- Error en el reporte -"
End If
End If
Do
CurrenthWnd = FindWindow(vbNullString, Trim$(sWindowTitle))
DoEvents
Loop Until CurrenthWnd = 0
End With
Set RPT = Nothing
Exit Sub
RutErrImp:
Set RPT = Nothing
If Err.Number = 20510 Then Resume Next
MsgBox Err.Description
End Sub
Luego pones el ocx de crystal en un formulario. y le pones de nombre Reporte.
Luego escribis esto en el formulario que necesita el reporte:
REP "Nombre del reporte", "Nombre del la pantalla", "", Como mostrarlo
Escribir este código en el modulo
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim CONN_REP As ADODB.Connection
Public Enum VistaReport
LJVentana = 0
LJImpresora = 1
LJArchivo = 2
End Enum
Public Sub REP(ByVal NOMBRE_DEL_REPORTE, ByVal TITULO, ByVal Filtro As String, Vista As VistaReport)
On Error GoTo RutErrImp
Dim RPT As Object
Dim CurrenthWnd As Long
Dim sWindowTitle As String
Dim AccessConnect As String
Dim liNumSubrep, liIdx As Integer
Set RPT = CreateObject("Crystal.CrystalReport")
With RPT
.ReportFileName = App.Path & "Reportes" & NOMBRE_DEL_REPORTE & ".rpt"
If Filtro <> "" Then
.SelectionFormula = Trim$(Filtro)
Debug.Print "Filtro reporte " & NOMBRE_DEL_REPORTE & " = " & Filtro
End If
sWindowTitle = TITULO
.DiscardSavedData = True
.WindowState = crptMaximized
.WindowTitle = sWindowTitle
.WindowShowProgressCtls = True
.WindowShowZoomCtl = True
.WindowShowRefreshBtn = True
.WindowShowPrintSetupBtn = True
.WindowMinButton = True
.WindowShowCancelBtn = True
.WindowShowExportBtn = True
.WindowMaxButton = True
.WindowState = crptMaximized
.WindowShowSearchBtn = True
.WindowShowGroupTree = True
.WindowAllowDrillDown = True
.Destination = Vista
.Connect = Conn
Screen.MousePointer = 11
Sleep 5000
Screen.MousePointer = 0
.PrintReport
If .LastErrorNumber > 0 Then
If .LastErrorNumber = 20507 Then
MsgBox .LastErrorNumber & ", " & .LastErrorString & " = " & NOMBRE_DEL_REPORTE, vbCritical, "GENERANDO EL REPORTE" & "- Error en el reporte -"
ElseIf .LastErrorNumber = 20510 Then
ElseIf .LastErrorNumber = 20515 Then
MsgBox Filtro & ", " & .LastErrorString
Else
MsgBox .LastErrorNumber & ", " & .LastErrorString, vbCritical, TITULO & "- Error en el reporte -"
End If
End If
Do
CurrenthWnd = FindWindow(vbNullString, Trim$(sWindowTitle))
DoEvents
Loop Until CurrenthWnd = 0
End With
Set RPT = Nothing
Exit Sub
RutErrImp:
Set RPT = Nothing
If Err.Number = 20510 Then Resume Next
MsgBox Err.Description
End Sub
Luego pones el ocx de crystal en un formulario. y le pones de nombre Reporte.
Luego escribis esto en el formulario que necesita el reporte:
REP "Nombre del reporte", "Nombre del la pantalla", "", Como mostrarlo
