Crystal Report - Como se hace CR8 y VB6

 
Vista:

Como se hace CR8 y VB6

Publicado por Carlos Cacho (1 intervención) el 22/07/2008 05:55:04
Hola amigos, soy principiante en CR y VB, ya he diseñado un reporte desde CR conectando via ODBC a SQL Server 2005, al momento de conectar le paso el username y el pass. Bien, luego deseo mostrar el informe en un applicacion VB usando el CRViewer, pero al momento de abrir el report en VB con:

Reporte.Open("c:Reporte1.rpt")

me tira "login failed - Acceso denegado para usuario xxxxxxx", mi pregunta es, como proporcionarle al reporte los datos de acceso para que me muestre el informe en vb. Otra cosa seria pasarle al reporte datos consultados en vb mediante un recorset, y usando la conexion abierta por mi aplicacion?, Desde ya agradezco cualquier cable que me puedan tirar, saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Como se hace CR8 y VB6

Publicado por marvin (85 intervenciones) el 22/07/2008 20:29:39
bueno, en tu caso usaste el CRViewer, este control es un poquitin mas dificil de manejar que el control de Crystal Report, bueno primero en el form q tenga el control esto ...

Private Sub Form_Load()
On Error GoTo ErrorN
Generar_Reporte
With CRViewer
.DisplayGroupTree = False
.EnableExportButton = True
.EnablePrintButton = True
.ReportSource = Reporte
.ViewReport
.Zoom 1
End With
Exit Sub
ErrorN:
MsgBox Err.Description
End Sub

'donde la funcion
Public Function Generar_Reporte(Optional rsTbl_Alterno As Variant) As Boolean
On Error GoTo ErrorN

Dim rsTbl As New ADODB.Recordset
Dim Application As CRAXDRT.Application

Screen.MousePointer = vbHourglass

Set Application = New CRAXDRT.Application
Set Reporte = Application.OpenReport(RptNombre)
Set rsTbl = New ADODB.Recordset
' MsgBox Consulta_SQL
rsTbl.Open CStr(Consulta_SQL), db, adOpenStatic, adLockOptimistic
' MsgBox (Val(rsTbl.RecordCount))
Reporte.Database.SetDataSource rsTbl
Reporte.DiscardSavedData
Reporte.ParameterFields(1).AddCurrentValue "" & ParamFechaIni & ""
Reporte.ParameterFields(2).AddCurrentValue "" & ParamFechaFin & ""
Reporte.ReadRecords
Screen.MousePointer = vbDefault
Application.OpenReport RptNombre, 1
Generar_Reporte = True
Exit Function

ErrorN:
MsgBox Err.Description, vbCritical, "Recolecciones"
Screen.MousePointer = vbDefault
Generar_Reporte = False
End Function

'desde el boton imprimir de tu formulario que lo invoca, algo como esto ...
Private Sub btnImprimir_Click()
Dim Consulta As String
Dim Condicion As String
Dim PathRep As String

On Error GoTo ErrorN

PathRep = CurDir + "ReportesRepRutasVehiculos.rpt"
TituloRep = "Reporte de Rutas Para Vehiculos - Pilotos"
ParamFechaIni = Format(dtFechaIni.Value, "dd/mm/yyyy")
ParamFechaFin = ""
Consulta = "SELECT a.Idrecoleccion, a.Hora, a.Direccion, a.Contacto, " & _
"a.Cantidadpiezas, a.Codcliente, b.Nomcliente, a.Codstatus, c.Nomstatus, " & _
"d.Nomtpieza, a.Codvehiculo, e.Piloto, a.Fecha, " & _
"e.Placa, f.codsector, f.nomsector FROM Recolecciones a " & _
"INNER JOIN Clientes b ON a.codcliente = b.codcliente " & _
"INNER JOIN Status c ON a.codstatus = c.codstatus " & _
"INNER JOIN Tipopieza d ON a.codtpieza = d.codtpieza " & _
"INNER JOIN Vehiculo e ON a.codvehiculo = e.codvehiculo " & _
"INNER JOIN Sector f ON e.codvehiculo = f.codvehiculo " & _
"WHERE a.codstatus in(1,3) and a.fecha <= '" & Format(dtFechaIni.Value, "dd/mm/yyyy") & "' "
Condicion = ""
If dcVehiculos.Enabled Then
Condicion = " AND e.codvehiculo = " & dcVehiculos.BoundText & " "
End If
Consulta = Consulta + Condicion + " ORDER BY a.codvehiculo ASC, c.codstatus DESC "

Call ImprimirDatos(Consulta, PathRep)
Exit Sub
ErrorN:
MsgBox Err.Description, vbCritical, "Recolecciones"
End Sub

'donde la funcion es ...
Public Sub ImprimirDatos(Query As String, PathReporte As String)
Screen.MousePointer = vbHourglass
Dim SQL As String
Dim v_Report As String

' Levanta la pantalla de vista preliminar de crystal Report
PreviewRepRecoPendFecha.GetParam Query, PathReporte
PreviewRepRecoPendFecha.Show
PreviewRepRecoPendFecha.Caption = TituloRep

Screen.MousePointer = vbDefault

End Sub

listo ...

lo q pasa aca es que creas un recordset que le envia como parametro al control ....
espero te sirva

salu2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar