VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_letras_estado 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Anular Letras"
   ClientHeight    =   4275
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   12435
   Icon            =   "Form_letras_estado.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4275
   ScaleWidth      =   12435
   Begin VB.Frame frm_estado 
      Caption         =   "Anular Letra"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1815
      Left            =   4440
      TabIndex        =   22
      Top             =   1440
      Visible         =   0   'False
      Width           =   3495
      Begin VB.CommandButton cmb_cancela 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1920
         TabIndex        =   25
         Top             =   1200
         Width           =   1215
      End
      Begin VB.CommandButton cmb_anula 
         Caption         =   "Aceptar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   360
         TabIndex        =   24
         Top             =   1200
         Width           =   1215
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Al aceptar la letra quedará NULA. ¿Desea Continuar?"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   360
         TabIndex        =   23
         Top             =   360
         Width           =   2895
      End
   End
   Begin VB.ListBox lst_nom_apo 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      ItemData        =   "Form_letras_estado.frx":2A8B2
      Left            =   4440
      List            =   "Form_letras_estado.frx":2A8B4
      TabIndex        =   1
      Top             =   720
      Visible         =   0   'False
      Width           =   4335
   End
   Begin VB.ListBox lst_rut_apo 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      ItemData        =   "Form_letras_estado.frx":2A8B6
      Left            =   9480
      List            =   "Form_letras_estado.frx":2A8B8
      TabIndex        =   0
      Top             =   720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Frame frm_option 
      Caption         =   "Opciones"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   855
      Left            =   120
      TabIndex        =   4
      Top             =   120
      Width           =   3255
      Begin VB.OptionButton Option1 
         Caption         =   "Por Apoderado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   1
         Left            =   1200
         TabIndex        =   6
         Top             =   480
         Value           =   -1  'True
         Width           =   1695
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Por Folio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   0
         Left            =   1200
         TabIndex        =   5
         Top             =   240
         Width           =   1695
      End
      Begin VB.Label Label4 
         Caption         =   "Seleccionar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Frame Frame_Cuponeras 
      Caption         =   "Cuponeras"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2535
      Left            =   120
      TabIndex        =   3
      Top             =   1080
      Width           =   12135
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid msh_letras 
         Height          =   2175
         Left            =   120
         TabIndex        =   21
         Top             =   240
         Width           =   11895
         _ExtentX        =   20981
         _ExtentY        =   3836
         _Version        =   393216
         FixedCols       =   0
         FocusRect       =   0
         SelectionMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin MSComctlLib.ProgressBar PgBar 
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   3720
      Width           =   12135
      _ExtentX        =   21405
      _ExtentY        =   661
      _Version        =   393216
      Appearance      =   1
      Min             =   1e-4
      Scrolling       =   1
   End
   Begin VB.Frame frm_apo 
      Caption         =   "Apoderado"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   855
      Left            =   3480
      TabIndex        =   13
      Top             =   120
      Width           =   8775
      Begin VB.TextBox txt_rut_apo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   5880
         TabIndex        =   15
         Top             =   360
         Width           =   1335
      End
      Begin VB.TextBox txt_nom_apo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   840
         TabIndex        =   14
         Top             =   360
         Width           =   4335
      End
      Begin VB.Label Label6 
         Caption         =   "Run"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   5520
         TabIndex        =   18
         Top             =   360
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "Nombre"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   17
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "Label1"
         Height          =   255
         Left            =   -120
         TabIndex        =   16
         Top             =   960
         Width           =   3615
      End
   End
   Begin VB.Frame frm_folio 
      ForeColor       =   &H00FF0000&
      Height          =   855
      Left            =   3480
      TabIndex        =   8
      Top             =   120
      Width           =   8775
      Begin VB.TextBox text_hasta 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         IMEMode         =   3  'DISABLE
         Left            =   4560
         TabIndex        =   10
         Top             =   360
         Width           =   1935
      End
      Begin VB.CommandButton cmb_buscar 
         Caption         =   "Buscar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   7320
         TabIndex        =   11
         Top             =   240
         Width           =   1335
      End
      Begin VB.TextBox text_desde 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         IMEMode         =   3  'DISABLE
         Left            =   1320
         TabIndex        =   9
         Top             =   360
         Width           =   1935
      End
      Begin VB.Label Label3 
         Caption         =   "Folio Hasta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3480
         TabIndex        =   26
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label14 
         Caption         =   "Folio Desde"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   12
         Top             =   360
         Width           =   855
      End
   End
   Begin VB.Label lbl_Apoderado 
      Caption         =   "Label3"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3600
      TabIndex        =   20
      Top             =   240
      Visible         =   0   'False
      Width           =   2655
   End
   Begin VB.Label lbl_Run 
      Caption         =   "Label9"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3600
      TabIndex        =   19
      Top             =   600
      Visible         =   0   'False
      Width           =   1215
   End
End
Attribute VB_Name = "Form_letras_estado"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean

Private Sub cmb_anula_Click()
    Dim sql As String
    Dim accion_detalle As String
    If MsgBox("Esta Seguro que Desea Eliminar la lefra Folio Nº:" & msh_letras.TextMatrix(msh_letras.Row, 0), vbYesNo + vbQuestion) = vbYes Then
        frm_estado.Visible = False
        msh_letras.TextMatrix(msh_letras.Row, 8) = "A"
        sql = "UPDATE fnza_letra_cab SET estado_letra = 'A' where folio_interno= " & msh_letras.TextMatrix(msh_letras.Row, 9)
        conn.Execute sql
        'Log fnza_historico_log
        accion_detalle = "La letra con folio físico " _
        & msh_letras.TextMatrix(msh_letras.Row, 0) & " a sido anulada"
        Call Inserta_Vitacora_Finanza(msh_letras.TextMatrix(msh_letras.Row, 6), _
        msh_letras.TextMatrix(msh_letras.Row, 1), "Anular Boleta", accion_detalle, 0, 0)
        'Fin de log
        cmb_cancela_Click
    End If
End Sub

Private Sub cmb_buscar_Click()
    Dim sql As String
    Dim rs As ADODB.Recordset
    Dim i As Integer
    IniGrillaLetras
    Set rs = New ADODB.Recordset
    
    sql = "SELECT fl.folio_fisico, fl.folio_interno, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as apo, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as alu, fl.fecha_letra, fl.agno, fl.folio_interno, fl.colegio,fl.run_apo,fl.run_alu,fl.estado_letra,fl.monto_letra  FROM fnza_letra_cab fl LEFT JOIN apoderados a on a.rut_apo = fl.run_apo left join postulantes p on fl.run_alu = p.ci_alu  where fl.folio_fisico >= " & text_desde.Text & " and fl.folio_fisico <= " & text_hasta.Text & ";"
    rs.Open sql, conn
    If rs.RecordCount = 0 Then
        MsgBox "no se han encontrado letras en ese rango"
        Exit Sub
    End If
    i = 1
    PgBar.Min = 0
    PgBar.Max = rs.RecordCount
'Rut apoderado|Nombre apoderado|Vencimiento|Año|Valor|RutAlumno|NombreAlumno|ClaveLetra|Folio_Int|Colegio
    While Not rs.EOF
        PgBar.Value = i
        msh_letras.Rows = i + 1
        msh_letras.TextMatrix(i, 0) = rs("folio_fisico")
        msh_letras.TextMatrix(i, 1) = rs("run_apo")
        msh_letras.TextMatrix(i, 2) = IIf(IsNull(rs("apo")), "", rs("apo"))
        msh_letras.TextMatrix(i, 3) = rs("fecha_letra")
        msh_letras.TextMatrix(i, 4) = rs("agno")
        msh_letras.TextMatrix(i, 5) = rs("monto_letra")
        msh_letras.TextMatrix(i, 6) = IIf(IsNull(rs("run_alu")), "", rs("run_alu"))
        msh_letras.TextMatrix(i, 7) = IIf(IsNull(rs("alu")), "", rs("alu"))
        msh_letras.TextMatrix(i, 8) = rs("estado_letra")
        msh_letras.TextMatrix(i, 9) = rs("folio_interno")
        msh_letras.TextMatrix(i, 10) = rs("colegio")
        If rs("estado_letra") = "A" Then
          msh_letras.Row = i
          For j = 1 To msh_letras.Cols - 1
              msh_letras.Col = j
              msh_letras.CellBackColor = &HC0C0FF
          Next j
        End If
        i = i + 1
        rs.MoveNext
    Wend
    
    
End Sub

Private Sub cmb_cancela_Click()
    frm_estado.Visible = False
    frm_apo.Enabled = True
    frm_estado.Enabled = True
    frm_option.Enabled = True
    msh_letras.Enabled = True
End Sub

Private Sub Form_Load()
    IniGrillaLetras
    Flag_sub = False
End Sub



Private Sub lst_nom_apo_DblClick()
    IniGrillaLetras
    
    Dim RC As ADODB.Recordset
    txt_nom_apo.Text = lst_nom_apo.Text

    Set RC = New ADODB.Recordset
    RC.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(txt_nom_apo.Text) & ")='" & txt_nom_apo.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_rut_apo.Text = RC("rut_apo")
    lbl_Run.Caption = RC("rut_apo")
    Flag_sub = False
    RC.Close
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = False
    llena_grilla_rut
End Sub

Private Sub lst_rut_apo_DblClick()
    IniGrillaLetras
    Dim RC As ADODB.Recordset
    txt_rut_apo.Text = lst_rut_apo.Text

    Set RC = New ADODB.Recordset
    RC.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre FROM `apoderados` where rut_apo='" & txt_rut_apo.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_nom_apo.Text = RC("nombre")
    lbl_Run.Caption = txt_rut_apo.Text
    Flag_sub = False
    RC.Close
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = False
    
    llena_grilla_rut
End Sub



Private Sub msh_letras_DblClick()
    If msh_letras.TextMatrix(msh_letras.Row, 8) = "V" Then
        frm_estado.Visible = True
        frm_apo.Enabled = False
        frm_folio.Enabled = False
        frm_option.Enabled = False
        msh_letras.Enabled = False
    End If
End Sub

Private Sub Option1_Click(Index As Integer)
    IniGrillaLetras
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = False
    txt_nom_apo.Text = ""
    txt_rut_apo.Text = ""
    text_desde.Text = ""
    text_hasta.Text = ""
    frm_folio.Visible = False
    frm_apo.Visible = False
    frm_folio.Enabled = True
    frm_apo.Enabled = True
    Select Case (Index)
        Case 0: frm_folio.Visible = True
        Case 1: frm_apo.Visible = True
    End Select
End Sub


Private Sub IniGrillaLetras()
    Me.msh_letras.Cols = 11
    Me.msh_letras.Rows = 2
    Me.msh_letras.Clear
'    Me.msh_letras.MergeCol(0) = False
'    Me.msh_letras.MergeCol(1) = False
'    Me.msh_letras.MergeCol(2) = True
'    Me.msh_letras.MergeCol(3) = True
'    Me.msh_letras.MergeCol(4) = False
'    Me.msh_letras.MergeCol(5) = False
'    Me.msh_letras.MergeCol(6) = False
'    Me.msh_letras.MergeCol(7) = False
'    Me.msh_letras.MergeCol(8) = False
'    Me.msh_letras.MergeCol(9) = False
'    Me.msh_letras.MergeCol(10) = False
                                    '0      1             2                 3             4    5      6           7             8            9         10
    Me.msh_letras.FormatString = " Folio  |Rut apoderado |Nombre apoderado| Vencimiento | Año |Valor |Rut Alumno| Nombre Alumno|Clave Letra| Folio_Int|Colegio"
    Me.msh_letras.ColWidth(0) = 1000
    Me.msh_letras.ColWidth(1) = 1000
    Me.msh_letras.ColWidth(2) = 3000 ' estara oculta ya que no se tomará en cuenta aun
    Me.msh_letras.ColWidth(3) = 1000
    Me.msh_letras.ColWidth(4) = 1000
    Me.msh_letras.ColWidth(5) = 1000
    Me.msh_letras.ColWidth(6) = 1000
    Me.msh_letras.ColWidth(7) = 3000
    Me.msh_letras.ColWidth(8) = 1000
    Me.msh_letras.ColWidth(9) = 1000
    Me.msh_letras.ColWidth(10) = 1000
End Sub



Private Sub text_desde_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        text_hasta.Text = text_desde.Text
        text_hasta.SetFocus
    End If
End Sub


Private Sub text_hasta_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        cmb_buscar_Click
    End If
End Sub

Private Sub txt_nom_apo_Change()
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If txt_nom_apo.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
        
    RC.Open "SELECT DISTINCT a.ape1_apo, a.ape2_apo, a.noms_apo FROM apoderados a, fnza_letra_cab fm where left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(txt_nom_apo.Text) & ")='" & txt_nom_apo.Text & "' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    lst_nom_apo.Clear
    While Not (RC.EOF)
        lst_nom_apo.AddItem RC("ape1_apo") & " " & RC("ape2_apo") & " " & RC("noms_apo")
        RC.MoveNext
    Wend
    RC.Close
    lst_nom_apo.Visible = True
    lst_rut_apo.Visible = False
    
End Sub

Private Sub txt_nom_apo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If (lst_nom_apo.ListCount = 0) Then
            Exit Sub
        End If
        lst_nom_apo.Selected(0) = True
        Flag_sub = True
        txt_nom_apo.Text = lst_nom_apo.Text
        Flag_sub = False
        Call lst_nom_apo_DblClick
    End If
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txt_rut_apo_Change()
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If txt_rut_apo.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
        
    RC.Open "SELECT DISTINCT a.rut_apo FROM apoderados a, fnza_letra_cab fm where a.rut_apo like '" & txt_rut_apo.Text & "%' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    lst_rut_apo.Clear
    While Not (RC.EOF)
        lst_rut_apo.AddItem RC("rut_apo")
        RC.MoveNext
    Wend
    RC.Close
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = True

End Sub

Private Sub txt_rut_apo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If (lst_rut_apo.ListCount = 0) Then
            Exit Sub
        End If
        lst_rut_apo.Selected(0) = True
        Flag_sub = True
        txt_rut_apo.Text = lst_rut_apo.Text
        Flag_sub = False
        Call lst_rut_apo_DblClick
    End If
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub llena_grilla_rut()
    Dim sql As String
    Dim rs As ADODB.Recordset
    Dim i As Integer
    
    Set rs = New ADODB.Recordset
    
    sql = "SELECT fl.folio_fisico, fl.folio_interno, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as apo, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as alu, fl.fecha_letra, fl.agno, fl.folio_interno, fl.colegio,fl.run_apo,fl.run_alu,fl.estado_letra,fl.monto_letra  FROM fnza_letra_cab fl LEFT JOIN apoderados a on a.rut_apo = fl.run_apo left join postulantes p on fl.run_alu = p.ci_alu  where fl.run_apo = '" & lbl_Run.Caption & "';"
    rs.Open sql, conn
    If rs.RecordCount = 0 Then
        MsgBox "no se han encontrado letras para ese apoderado"
        Exit Sub
    End If
    i = 1
    PgBar.Min = 1
    PgBar.Max = rs.RecordCount
    
'Rut apoderado|Nombre apoderado|Vencimiento|Año|Valor|RutAlumno|NombreAlumno|ClaveLetra|Folio_Int|Colegio
    While Not rs.EOF
        PgBar.Value = i
        msh_letras.Rows = i + 1
        msh_letras.TextMatrix(i, 0) = rs("folio_fisico")
        msh_letras.TextMatrix(i, 1) = rs("run_apo")
        msh_letras.TextMatrix(i, 2) = rs("apo")
        msh_letras.TextMatrix(i, 3) = rs("fecha_letra")
        msh_letras.TextMatrix(i, 4) = rs("agno")
        msh_letras.TextMatrix(i, 5) = rs("monto_letra")
        msh_letras.TextMatrix(i, 6) = rs("run_alu")
        msh_letras.TextMatrix(i, 7) = rs("alu")
        msh_letras.TextMatrix(i, 8) = rs("estado_letra")
        msh_letras.TextMatrix(i, 9) = rs("folio_interno")
        msh_letras.TextMatrix(i, 10) = rs("colegio")
        If rs("estado_letra") = "A" Then
          msh_letras.Row = i
          For j = 0 To msh_letras.Cols - 1
              msh_letras.Col = j
              msh_letras.CellBackColor = &HC0C0FF
          Next j
        End If
        rs.MoveNext
        i = i + 1
    Wend
End Sub
