Private Sub KewImprimir_Click()
'Variables para calculos de valores
Dim total As Double, iva As Double, acumulador As Double, longitud As Integer
Dim alto, ancho, posX, posY, AltoCm, AnchoCm, posiX, PosiiY As Double
'conexion db
Set rst10 = New ADODB.Recordset: Set rst10.ActiveConnection = DataEnvironment1.Connection1 'conexion
NCOM10 = "SELECT * FROM IVDIA_FACTURA_VENTA WHERE IEFAVE_IDEN ='7610'": CONSULTA_X (NCOM10) 'query
rst10.MoveFirst
'se asigana cada rst10 al textBox necesario
txtCliente = (Trim(rst10!FECLIE_APEC) + " " + Trim(rst10!FECLIE_NOMC))
txtIdentificacion = Trim(rst10!FECLIE_CODC)
txtDireccion = Trim(rst10!FECLIE_DIRC)
txtFecha = (Trim(rst10!IEFAVE_FEMI) + " " + Trim(rst10!IEFAVE_HORA))
txtTelefono = Trim(rst10!FECLIE_TELC)
txtTipoPago = Trim(rst10!TipoVta)
txtEfectivo = Trim(rst10!IEFAVE_TOTA)
txtVendedor = Trim(rst10!EmpRep)
txtCIva = Trim(rst10!IEFAVE_CIVA)
txtSIva = Trim(rst10!IEFAVE_SIVA)
txtDescuento = Trim(rst10!IEFAVE_DSCT)
'inicia msflexgrid
lista.Rows = 1
lista.ColAlignment(0) = flexAlignCenterCenter
lista.ColAlignment(1) = flexAlignLeftCenter
lista.ColAlignment(2) = flexAlignRightCenter
lista.ColAlignment(3) = flexAlignRightCenter
If rst10.EOF = False Then
'for para llenar msflexgrid
For I = 1 To rst10.RecordCount
lista.Rows = lista.Rows + 1
lista.TextMatrix(I, 0) = Trim(rst10!IEDEFV_CANG)
longitud = Len(Trim(rst10!IEPROD_DESP))
If longitud >= 20 Then
lista.TextMatrix(I, 1) = Mid(Trim(rst10!IEPROD_DESP), 1, 14)
Else
lista.TextMatrix(I, 1) = Trim(rst10!IEPROD_DESP)
End If
lista.TextMatrix(I, 2) = Trim(rst10!IEDEFV_VUNI)
lista.TextMatrix(I, 3) = (Trim(rst10!IEDEFV_CANG) * Trim(rst10!IEDEFV_VUNI))
acumulador = acumulador + lista.TextMatrix(I, 3)
'aqui cambia de fila
rst10.MoveNext
If I = rst10.RecordCount Then
iva = acumulador * 0.12
total = acumulador + iva
lista.Rows = lista.Rows + 5
lista.TextMatrix(I + 1, 2) = "BsImp:"
lista.TextMatrix(I + 1, 3) = acumulador
lista.TextMatrix(I + 2, 2) = "C/Iva:"
lista.TextMatrix(I + 2, 3) = txtCIva
lista.TextMatrix(I + 3, 2) = "S/Iva:"
lista.TextMatrix(I + 3, 3) = txtSIva
lista.TextMatrix(I + 4, 2) = "Iva: "
lista.TextMatrix(I + 4, 3) = iva
lista.TextMatrix(I + 5, 2) = "Total:"
lista.TextMatrix(I + 5, 3) = total
End If
Next I
'Calculos de valores
txtBaseImp = acumulador
txtIva = iva
txtVTotal = total
End If
'consulta para las coordenadas
Set rst10 = New ADODB.Recordset: Set rst10.ActiveConnection = DataEnvironment1.Connection1 'conexion
NCOM10 = "select * from pedia_demo inner join PEDIA_MOLD on pedia_demo.PEMOLD_IDEN = pedia_mold.PEMOLD_IDEN where .pedia_demo.PEMOLD_IDEN = '1'": CONSULTA_X (NCOM10) 'query
rst10.MoveFirst
'llenar grid Posiciones
posiciones.Rows = 1
If rst10.EOF = False Then
For I = 1 To rst10.RecordCount
posiciones.Rows = posiciones.Rows + 1
posiciones.TextMatrix(I, 0) = Trim(rst10!PEDEMO_IDEN)
posiciones.TextMatrix(I, 1) = Trim(rst10!PEMOLD_IDEN)
posiciones.TextMatrix(I, 2) = Trim(rst10!PEDEMO_POSX)
posiciones.TextMatrix(I, 3) = Trim(rst10!PEDEMO_POSY)
posiciones.TextMatrix(I, 4) = Trim(rst10!PEDEMO_VISI)
posiciones.TextMatrix(I, 5) = Trim(rst10!PEDEMO_ALTO)
posiciones.TextMatrix(I, 6) = Trim(rst10!PEDEMO_ANCH)
posiciones.TextMatrix(I, 7) = Trim(rst10!PEDEMO_CODI)
posiciones.TextMatrix(I, 8) = Trim(rst10!PEMOLD_IDEN)
posiciones.TextMatrix(I, 9) = Trim(rst10!PEMOLD_NOMP)
posiciones.TextMatrix(I, 10) = Trim(rst10!PEMOLD_TIDO)
posiciones.TextMatrix(I, 11) = Trim(rst10!PEMOLD_ACTI)
posiciones.TextMatrix(I, 12) = Trim(rst10!PEMOLD_ALTO)
posiciones.TextMatrix(I, 13) = Trim(rst10!PEMOLD_ANCH)
'aqui cambia de fila
rst10.MoveNext
Next I
End If
'Impresion, primero se agrega variable
Dim iFila, iCol As Integer: Dim posiY, ultiEspacio As Double
Dim XObjeto, YObjeto, altoO, anchoO As Double
Dim prefijo As String
Dim variable2 As Integer
Printer.ScaleMode = vbCentimeters: Printer.FontSize = 8 ': Printer.Width = 13 ': Printer.Font = "Draft 10cpi"
'ciclo para el encabezado
For I = 1 To posiciones.Rows - 1
XObjeto = Trim(posiciones.TextMatrix(I, 2))
YObjeto = Trim(posiciones.TextMatrix(I, 3))
' altoO = Trim(posiciones.TextMatrix(I, 5))
' anchoO = Trim(posiciones.TextMatrix(I, 6))
variable2 = Trim(posiciones.TextMatrix(I, 7))
'condicion que transforma la variable 2 a objeto de la lista
If variable2 = 0 Then
Set varObj = lblNombreCliente
ElseIf variable2 = 1 Then
Set varObj = txtCliente
ElseIf variable2 = 2 Then
Set varObj = lblIdentificacion
ElseIf variable2 = 3 Then
Set varObj = txtIdentificacion
ElseIf variable2 = 4 Then
Set varObj = lblDireccion
ElseIf variable2 = 5 Then
Set varObj = txtDireccion
ElseIf variable2 = 6 Then
Set varObj = lblFecha
ElseIf variable2 = 7 Then
Set varObj = txtFecha
ElseIf variable2 = 8 Then
Set varObj = lblTelefono
ElseIf variable2 = 9 Then
Set varObj = txtTelefono
ElseIf variable2 = 10 Then
Set varObj = lblTipoPago
ElseIf variable2 = 11 Then
Set varObj = txtTipoPago
ElseIf variable2 = 12 Then
Set varObj = lblTotal
ElseIf variable2 = 13 Then
Set varObj = txtVTotal
ElseIf variable2 = 14 Then
Set varObj = lblEfectivo
ElseIf variable2 = 15 Then
Set varObj = txtEfectivo
ElseIf variable2 = 16 Then
Set varObj = lblIva
ElseIf variable2 = 17 Then
Set varObj = txtIva
ElseIf variable2 = 18 Then
Set varObj = lblDolares
ElseIf variable2 = 19 Then
Set varObj = txtDolares
ElseIf variable2 = 20 Then
Set varObj = lblCambio
ElseIf variable2 = 21 Then
Set varObj = txtCambio
ElseIf variable2 = 22 Then
Set varObj = lblCheque
ElseIf variable2 = 23 Then
Set varObj = txtCheque
ElseIf variable2 = 24 Then
Set varObj = lblDeposito
ElseIf variable2 = 25 Then
Set varObj = txtDeposito
ElseIf varaible2 = 26 Then
Set varObj = lblTarjeta
ElseIf varaible2 = 27 Then
Set varObj = txtTarjeta
ElseIf variable2 = 28 Then
Set varObj = lblCIva
ElseIf varaible2 = 29 Then
Set varObj = txtCIva
ElseIf variable2 = 30 Then
Set varObj = lblSIva
ElseIf varaible2 = 31 Then
Set varObj = txtSIva
ElseIf variable2 = 32 Then
Set varObj = lblDiElectronico
ElseIf variable2 = 33 Then
Set varObj = txtDElectronico
ElseIf variable2 = 34 Then
Set varObj = lblDescuento
ElseIf varaible2 = 35 Then
Set varObj = txtDescuento
ElseIf variable2 = 36 Then
Set varObj = lblVende
ElseIf varaible2 = 37 Then
Set varObj = txtVendedor
ElseIf varaible2 = 38 Then
Set varObj = lblAlto
ElseIf varaible2 = 39 Then
Set varObj = txtAlto
ElseIf variable2 = 40 Then
Set varObj = lblAncho
ElseIf varaible2 = 41 Then
Set varObj = txtAncho
ElseIf variable2 = 42 Then
Set varObj = lblEspaciado
ElseIf variable2 = 43 Then
Set varObj = txtEspaciado
ElseIf varaible2 = 44 Then
Set varObj = lblPosicionY
ElseIf varaible2 = 45 Then
Set varObj = txtPosY
ElseIf varaible2 = 46 Then
Set varObj = lblPosicionX
ElseIf variable2 = 47 Then
Set varObj = txtPosX
' ElseIf variable2 = 57 Then
' Set varObj = lista
ElseIf variable2 = 58 Then
Set varObj = lblBaseImp
ElseIf varaible2 = 59 Then
Set varObj = txtBaseImp
End If
'if para impresion
With Printer
.CurrentX = XObjeto / 567
.CurrentY = YObjeto / 567
'.Height = altoO / 567
'.Width = anchoO / 567
Printer.Print varObj
ultiEspacio = varObj.TOP / 567
End With
Next I
'calculo el tamaño del ultimo campo
'ultiEspacio = varObj.TOP / 567
'inicio de imrpesion de detalle
posiY = ultiEspacio + 1
For iFila = 0 To lista.Rows - 1
PosImp Val(posiY), 0, Trim(lista.TextMatrix(iFila, 0)) 'cantidad
PosImp Val(posiY), 0.9, Trim(lista.TextMatrix(iFila, 1)) 'detalle
PosImp Val(posiY), 5.5, Format(Format(Trim(lista.TextMatrix(iFila, 2)), "###0.0000"), "@@@@@@@") 'V unitario
PosImp Val(posiY), 7.9, Format(Format(Trim(lista.TextMatrix(iFila, 3)), "###0.0000"), "@@@@@@@") 'Vtotal
posiY = posiY + 0.5: If posiY > 28 Then posiY = 2: Printer.NewPage
Next iFila
'aqui hace la magia para imprimir
Printer.EndDoc
End Sub