Option Explicit
Private crApp As New CRAXDRT.Application
Private crReport As New CRAXDRT.Report
Private rs_Facturas As New ADODB.Recordset
Private rs_Clientes As New ADODB.Recordset
Private rs_Marcas As New ADODB.Recordset
Private rs_Movimien As New ADODB.Recordset
Private rs_Compania As New ADODB.Recordset
Private Sub Form_Load()
On Error GoTo Errores
Screen.MousePointer = vbHourglass
'Preparo el informe
PrepararInforme
crReport.PrintOut True, 1
Screen.MousePointer = vbDefault
'Cierro los recordset
If rs_Clientes.State = 1 Then rs_Clientes.Close
If rs_Compania.State = 1 Then rs_Compania.Close
If rs_Facturas.State = 1 Then rs_Facturas.Close
If rs_Marcas.State = 1 Then rs_Marcas.Close
If rs_Movimien.State = 1 Then rs_Movimien.Close
Set rs_Clientes = Nothing
Set rs_Compania = Nothing
Set rs_Facturas = Nothing
Set rs_Marcas = Nothing
Set rs_Movimien = Nothing
Set crReport = Nothing
Exit Sub
Errores:
Select Case Err.Number
Case -2147467261
Resume Next
Case Else
Screen.MousePointer = vbDefault
MsgBox Err.Description, vbCritical + vbOKOnly
Unload Me
End Select
End Sub
Private Sub PrepararInforme()
On Error GoTo ErrHandler
Set crReport = crApp.OpenReport(App.Path & "\Informes\Factura.rpt", 1)
crReport.DiscardSavedData
Dim SQL As String
'SQL Tablas Clientes
SQL = "SELECT * FROM Clientes WHERE Entrada = " & CLng(Entrada)
rs_Clientes.Open SQL, cn, adOpenDynamic, adLockReadOnly
'SQL Tabla Compañías
SQL = "SELECT * FROM Compania WHERE Codigo_Compania = '" & rs_Clientes![Compania_Seguro] & "'"
rs_Compania.Open SQL, cn, adOpenDynamic, adLockReadOnly
'SQL Tabla Facturas
SQL = "SELECT * FROM Facturas WHERE Entrada = " & CLng(Entrada) & " ORDER BY Importe"
rs_Facturas.Open SQL, cn, adOpenDynamic, adLockReadOnly
'SQL Tablas Marcas
SQL = "SELECT * FROM Marcas WHERE Marcas.Marca = '" & rs_Clientes![Vehiculo] & "'"
rs_Marcas.Open SQL, cn, adOpenDynamic, adLockReadOnly
'SQL Tablas Movimien
SQL = "SELECT * FROM Movimien WHERE Entrada = " & CLng(Entrada) & " ORDER BY Tipo_Movimiento DESC"
rs_Movimien.Open SQL, cn, adOpenDynamic, adLockReadOnly
crReport.Database.Tables(1).SetDataSource rs_Clientes
crReport.Database.Tables(2).SetDataSource rs_Movimien
crReport.Database.Tables(3).SetDataSource rs_Facturas
crReport.Database.Tables(4).SetDataSource rs_Compania
crReport.Database.Tables(5).SetDataSource rs_Marcas
Exit Sub
ErrHandler:
If Err.Number = -2147206461 Then
MsgBox "El archivo de reporte no se encuentra, restáurelo de los discos de instalación", _
vbCritical + vbOKOnly
Else
MsgBox Err.Description, vbCritical + vbOKOnly
Unload Me
End If
Screen.MousePointer = vbDefault
End Sub