VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form Form_Letras_Principal 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Letras de Cambio"
   ClientHeight    =   8505
   ClientLeft      =   -4770
   ClientTop       =   450
   ClientWidth     =   14505
   Icon            =   "Form_Letras_Principal.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8505
   ScaleWidth      =   14505
   Begin VB.Frame Frame_Individual_Letras 
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   7575
      Left            =   120
      TabIndex        =   36
      Top             =   120
      Width           =   13815
      Begin VB.Frame Frame_IndBusq_Letras 
         Caption         =   "Búsqueda de Apoderados"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   4335
         Left            =   0
         TabIndex        =   37
         Top             =   0
         Width           =   13695
         Begin VB.ListBox Lst_IndRutApo_Letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1110
            Left            =   8280
            TabIndex        =   43
            Top             =   600
            Visible         =   0   'False
            Width           =   1695
         End
         Begin VB.ListBox Lst_IndNomApo_Letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1110
            Left            =   1080
            TabIndex        =   38
            Top             =   600
            Visible         =   0   'False
            Width           =   6375
         End
         Begin VB.ListBox Lst_Indtipoalu_letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   2220
            ItemData        =   "Form_Letras_Principal.frx":2A8B2
            Left            =   120
            List            =   "Form_Letras_Principal.frx":2A8BF
            Style           =   1  'Checkbox
            TabIndex        =   98
            Top             =   1920
            Width           =   2175
         End
         Begin VB.ComboBox Cmb_Indcolegio_letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   4200
            Locked          =   -1  'True
            Style           =   1  'Simple Combo
            TabIndex        =   84
            Text            =   "cmb_indcolegio_letras"
            Top             =   1080
            Width           =   3255
         End
         Begin MSFlexGridLib.MSFlexGrid Grd_IndAlu_Letras 
            Height          =   2655
            Left            =   2400
            TabIndex        =   78
            Top             =   1560
            Width           =   11175
            _ExtentX        =   19711
            _ExtentY        =   4683
            _Version        =   393216
            GridLines       =   2
            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
         End
         Begin VB.CheckBox Chk_titular_letras 
            Caption         =   "Apoderado es Titular"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   10080
            TabIndex        =   52
            Top             =   360
            Width           =   1335
         End
         Begin VB.TextBox txt_ciudadapo_letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   50
            Top             =   1080
            Width           =   2175
         End
         Begin VB.TextBox txt_comunaapo_letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   8280
            Locked          =   -1  'True
            TabIndex        =   48
            Top             =   720
            Width           =   1695
         End
         Begin VB.TextBox txt_dirapo_Letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            Locked          =   -1  'True
            TabIndex        =   46
            Top             =   720
            Width           =   6375
         End
         Begin VB.ComboBox Cmb_IndAnho_Letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   8280
            Style           =   2  'Dropdown List
            TabIndex        =   44
            Top             =   1080
            Width           =   1695
         End
         Begin VB.TextBox Txt_IndRutApo_Letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   8280
            TabIndex        =   40
            Top             =   360
            Width           =   1695
         End
         Begin VB.TextBox Txt_IndNomApo_Letra 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            TabIndex        =   39
            Top             =   360
            Width           =   6375
         End
         Begin VB.CommandButton btn_otro_apod 
            Caption         =   "Otro Apoderado"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   975
            Left            =   12000
            Picture         =   "Form_Letras_Principal.frx":2A8FE
            Style           =   1  'Graphical
            TabIndex        =   87
            Top             =   360
            Width           =   1455
         End
         Begin VB.Label Label14 
            Caption         =   "Colegio"
            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        =   85
            Top             =   1080
            Width           =   975
         End
         Begin VB.Label Label22 
            Caption         =   "Tipo de Alumnos"
            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        =   77
            Top             =   1680
            Width           =   2055
         End
         Begin VB.Label Label13 
            Caption         =   "Ciudad"
            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        =   51
            Top             =   1080
            Width           =   735
         End
         Begin VB.Label Label12 
            Caption         =   "Comuna"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   7560
            TabIndex        =   49
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label11 
            Caption         =   "Domicilio"
            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        =   47
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label10 
            Caption         =   "Año"
            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            =   7560
            TabIndex        =   45
            Top             =   1080
            Width           =   495
         End
         Begin VB.Label Label9 
            Caption         =   "Apoderado"
            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        =   42
            Top             =   360
            Width           =   975
         End
         Begin VB.Label Label8 
            Caption         =   "Rut"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   7560
            TabIndex        =   41
            Top             =   360
            Width           =   495
         End
      End
      Begin VB.Frame Frame_Aceptante_Letras 
         Caption         =   "Datos del Titular"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1575
         Left            =   0
         TabIndex        =   53
         Top             =   4440
         Width           =   13695
         Begin VB.TextBox txt_ape_mat_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   6360
            TabIndex        =   82
            Top             =   720
            Width           =   3975
         End
         Begin VB.TextBox txt_ape_pat_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            TabIndex        =   80
            Top             =   720
            Width           =   4095
         End
         Begin VB.ComboBox cmb_codgeo_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   11160
            Style           =   1  'Simple Combo
            TabIndex        =   79
            Top             =   1080
            Visible         =   0   'False
            Width           =   2295
         End
         Begin VB.ComboBox cmb_ciudad_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   11160
            Style           =   1  'Simple Combo
            TabIndex        =   58
            Text            =   "cmb_ciudad_acep"
            Top             =   720
            Width           =   2295
         End
         Begin VB.TextBox txt_rut_acep 
            Alignment       =   1  'Right Justify
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            TabIndex        =   57
            Top             =   360
            Width           =   1575
         End
         Begin VB.TextBox txt_nom_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   3600
            TabIndex        =   56
            Top             =   360
            Width           =   6735
         End
         Begin VB.ComboBox Cmb_Comuna_Acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   11160
            Style           =   2  'Dropdown List
            TabIndex        =   55
            Top             =   360
            Width           =   2295
         End
         Begin VB.TextBox txt_dir_acep 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1080
            TabIndex        =   54
            Top             =   1080
            Width           =   9255
         End
         Begin VB.Label Label23 
            Caption         =   "Ap.Materno"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5400
            TabIndex        =   83
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label17 
            Caption         =   "Ap.Paterno"
            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        =   81
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label21 
            Caption         =   "Ciudad"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   10440
            TabIndex        =   63
            Top             =   720
            Width           =   975
         End
         Begin VB.Label Label18 
            Caption         =   "Rut"
            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        =   62
            Top             =   360
            Width           =   495
         End
         Begin VB.Label Label19 
            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            =   2880
            TabIndex        =   61
            Top             =   360
            Width           =   975
         End
         Begin VB.Label Label16 
            Caption         =   "Comuna"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   10440
            TabIndex        =   60
            Top             =   360
            Width           =   975
         End
         Begin VB.Label Label15 
            Caption         =   "Domicilio"
            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        =   59
            Top             =   1080
            Width           =   975
         End
      End
      Begin VB.Frame Frame1 
         Caption         =   "Generación de Letras"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1335
         Left            =   0
         TabIndex        =   64
         Top             =   6120
         Width           =   13695
         Begin VB.TextBox txt_indFolio_inicial 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2040
            TabIndex        =   69
            Top             =   840
            Width           =   1575
         End
         Begin VB.CommandButton Btn_IndProcesar 
            Caption         =   "&Generar Letras"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   975
            Left            =   12120
            Picture         =   "Form_Letras_Principal.frx":2AF24
            Style           =   1  'Graphical
            TabIndex        =   68
            Top             =   240
            Width           =   1455
         End
         Begin VB.Frame Frame5 
            Height          =   1095
            Left            =   3840
            TabIndex        =   65
            Top             =   120
            Width           =   2895
            Begin VB.OptionButton Opt_IndCta_Mayor_Menor 
               Caption         =   "Cuenta total en hermano M&enor"
               Enabled         =   0   'False
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   375
               Index           =   0
               Left            =   120
               TabIndex        =   67
               Top             =   600
               Width           =   2655
            End
            Begin VB.OptionButton Opt_IndCta_Mayor_Menor 
               Caption         =   "Cuenta total en hermano M&ayor"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   375
               Index           =   1
               Left            =   120
               TabIndex        =   66
               Top             =   240
               Value           =   -1  'True
               Width           =   2655
            End
         End
         Begin MSComCtl2.DTPicker Dtp_IndFecha_emision 
            Height          =   375
            Left            =   2040
            TabIndex        =   70
            Top             =   360
            Width           =   1575
            _ExtentX        =   2778
            _ExtentY        =   661
            _Version        =   393216
            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
            Format          =   50987009
            CurrentDate     =   38617
         End
         Begin VB.Label Label25 
            Caption         =   "Folio Inicial"
            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        =   72
            Top             =   840
            Width           =   1455
         End
         Begin VB.Label Label24 
            Caption         =   "Fecha de Emision"
            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        =   71
            Top             =   360
            Width           =   1815
         End
      End
   End
   Begin VB.Frame Frame_Masivo_Letras 
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   7695
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   13935
      Begin VB.Frame Frame_Inicio 
         Caption         =   "Búsqueda de Información Masiva"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1695
         Left            =   120
         TabIndex        =   1
         Top             =   120
         Width           =   6375
         Begin VB.ComboBox Cmb_Colegio_Letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   1080
            Locked          =   -1  'True
            Style           =   1  'Simple Combo
            TabIndex        =   18
            Text            =   "Cmb_Colegio_Letras"
            Top             =   360
            Width           =   3375
         End
         Begin VB.Frame Frame3 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00FF0000&
            Height          =   855
            Left            =   120
            TabIndex        =   17
            Top             =   720
            Width           =   4335
            Begin VB.OptionButton Opt_Menu_Letras 
               Caption         =   "Alumnos Nuevos"
               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            =   360
               TabIndex        =   3
               Top             =   240
               Width           =   2535
            End
            Begin VB.OptionButton Opt_Menu_Letras 
               Caption         =   "Alumnos Antiguos"
               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            =   360
               TabIndex        =   4
               Top             =   480
               Width           =   2535
            End
         End
         Begin VB.CommandButton Btn_Menu_Letras_Salir 
            Caption         =   "&Salir"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Left            =   4680
            Picture         =   "Form_Letras_Principal.frx":2B49E
            Style           =   1  'Graphical
            TabIndex        =   2
            Top             =   240
            Width           =   1575
         End
         Begin VB.Label Label20 
            Caption         =   "Colegio"
            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        =   86
            Top             =   360
            Width           =   975
         End
      End
      Begin VB.Frame Frame_Proceso 
         Caption         =   "Generación de Letras"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1575
         Left            =   6600
         TabIndex        =   73
         Top             =   6000
         Width           =   7215
         Begin VB.CommandButton Btn_Procesar 
            Caption         =   "&Generar Letras"
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Left            =   5520
            Picture         =   "Form_Letras_Principal.frx":2B806
            Style           =   1  'Graphical
            TabIndex        =   14
            Top             =   600
            Width           =   1575
         End
         Begin VB.TextBox Txt_Folio_Inicial 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1680
            TabIndex        =   11
            Top             =   840
            Width           =   1575
         End
         Begin MSComCtl2.DTPicker Dtp_Fecha_Emision 
            Height          =   375
            Left            =   1680
            TabIndex        =   10
            Top             =   360
            Width           =   1575
            _ExtentX        =   2778
            _ExtentY        =   661
            _Version        =   393216
            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
            Format          =   50987009
            CurrentDate     =   40808
         End
         Begin VB.Frame Frame2 
            Height          =   855
            Left            =   5760
            TabIndex        =   74
            Top             =   600
            Visible         =   0   'False
            Width           =   1215
            Begin VB.OptionButton Opt_Cta_Mayor_Menor 
               Caption         =   "Cuenta total en hermano M&enor"
               Enabled         =   0   'False
               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            =   240
               TabIndex        =   13
               Top             =   480
               Visible         =   0   'False
               Width           =   3375
            End
            Begin VB.OptionButton Opt_Cta_Mayor_Menor 
               Caption         =   "Cuenta total en hermano M&ayor"
               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            =   240
               TabIndex        =   12
               Top             =   240
               Value           =   -1  'True
               Visible         =   0   'False
               Width           =   3255
            End
         End
         Begin VB.Label Label7 
            Caption         =   "Apoderados a Procesar : "
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00C00000&
            Height          =   255
            Left            =   3480
            TabIndex        =   95
            Top             =   360
            Width           =   2055
         End
         Begin VB.Label Lbl_Reg_Encontrados 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   5640
            TabIndex        =   96
            Top             =   360
            Width           =   735
         End
         Begin VB.Label Label5 
            Caption         =   "Folio Inicial"
            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        =   76
            Top             =   840
            Width           =   1455
         End
         Begin VB.Label Label4 
            Caption         =   "Fecha de Emisión"
            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        =   75
            Top             =   360
            Width           =   1455
         End
      End
      Begin VB.Frame Frame_muestraalumnos 
         Caption         =   "Listado Alumnos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   5775
         Left            =   6600
         TabIndex        =   91
         Top             =   120
         Visible         =   0   'False
         Width           =   7215
         Begin VB.CommandButton Btn_CartasVal 
            Caption         =   "Cartas Valorización"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   3840
            TabIndex        =   16
            Top             =   5160
            Visible         =   0   'False
            Width           =   1575
         End
         Begin VB.CommandButton Btn_Contratos 
            Caption         =   "Generar Contratos"
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Left            =   5520
            Picture         =   "Form_Letras_Principal.frx":2BBEB
            Style           =   1  'Graphical
            TabIndex        =   15
            Top             =   4800
            Width           =   1575
         End
         Begin MSFlexGridLib.MSFlexGrid grd_alumnos 
            Height          =   4455
            Left            =   120
            TabIndex        =   92
            Top             =   240
            Width           =   7035
            _ExtentX        =   12409
            _ExtentY        =   7858
            _Version        =   393216
            Cols            =   12
            FixedCols       =   0
            BackColor       =   16777215
            SelectionMode   =   1
            FormatString    =   "^Nombre Apoderado|^Rut|^Nombre Alumno|^rutapo|^dir|^comuna|^esmayor|^in_cup|^asignada"
            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
         End
         Begin VB.Shape Shape1 
            BackColor       =   &H00C0FFC0&
            BackStyle       =   1  'Opaque
            FillColor       =   &H000000FF&
            Height          =   255
            Index           =   1
            Left            =   240
            Shape           =   1  'Square
            Top             =   4920
            Width           =   255
         End
         Begin VB.Label Label10 
            Caption         =   "Alumno con 100% Beca"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   2
            Left            =   600
            TabIndex        =   100
            Top             =   5280
            Width           =   2415
         End
         Begin VB.Shape Shape1 
            BackColor       =   &H00C0FFFF&
            BackStyle       =   1  'Opaque
            FillColor       =   &H000000FF&
            Height          =   255
            Index           =   0
            Left            =   240
            Shape           =   1  'Square
            Top             =   5280
            Width           =   255
         End
         Begin VB.Label Label10 
            Caption         =   "Alumno Sin Problemas"
            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            =   600
            TabIndex        =   99
            Top             =   4920
            Width           =   2295
         End
      End
      Begin VB.Frame Frame_Busqueda_Nuevos 
         Caption         =   "Alumnos Nuevos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   2775
         Left            =   120
         TabIndex        =   19
         Top             =   1920
         Width           =   6375
         Begin VB.ComboBox Cmb_FechaBus_Nuevos 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   4680
            Style           =   2  'Dropdown List
            TabIndex        =   93
            Top             =   840
            Width           =   1335
         End
         Begin VB.ComboBox Cmb_IndTipoAluNew_Mas 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            ItemData        =   "Form_Letras_Principal.frx":2C165
            Left            =   1680
            List            =   "Form_Letras_Principal.frx":2C167
            Style           =   2  'Dropdown List
            TabIndex        =   89
            Top             =   2280
            Width           =   2535
         End
         Begin VB.CommandButton Btn_Limpiar 
            Caption         =   "Limpiar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Index           =   2
            Left            =   4560
            TabIndex        =   88
            Top             =   2160
            Width           =   1575
         End
         Begin VB.Frame Frame_Tipo_Fechas 
            Height          =   615
            Left            =   120
            TabIndex        =   24
            Top             =   600
            Width           =   4095
            Begin VB.OptionButton Opt_Tipo_Fecha 
               Caption         =   "Fecha Evaluacion"
               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            =   2160
               TabIndex        =   26
               Top             =   240
               Width           =   1815
            End
            Begin VB.OptionButton Opt_Tipo_Fecha 
               Caption         =   "Fecha Postulacion"
               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            =   120
               TabIndex        =   25
               Top             =   240
               Width           =   1815
            End
         End
         Begin VB.ComboBox cmb_anho_letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Index           =   0
            Left            =   1680
            Style           =   2  'Dropdown List
            TabIndex        =   23
            Top             =   240
            Width           =   1335
         End
         Begin VB.CommandButton Btn_Buscar_Datos 
            Caption         =   "Buscar Datos"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   735
            Index           =   0
            Left            =   4560
            Picture         =   "Form_Letras_Principal.frx":2C169
            Style           =   1  'Graphical
            TabIndex        =   22
            Top             =   1320
            Width           =   1575
         End
         Begin VB.ComboBox Cmb_CodEns_Letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Index           =   0
            Left            =   1680
            Style           =   2  'Dropdown List
            TabIndex        =   21
            Top             =   1320
            Width           =   2535
         End
         Begin VB.ComboBox Cmb_NumGra_LEtras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Index           =   0
            Left            =   1680
            Style           =   2  'Dropdown List
            TabIndex        =   20
            Top             =   1800
            Width           =   1095
         End
         Begin VB.Label Label1 
            Caption         =   "Fecha de búsqueda"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   4680
            TabIndex        =   94
            Top             =   600
            Width           =   1455
         End
         Begin VB.Label Label26 
            Caption         =   "Tipo de Alumnos"
            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        =   90
            Top             =   2280
            Width           =   1575
         End
         Begin VB.Label Label2 
            Caption         =   "Año Postulación"
            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        =   29
            Top             =   360
            Width           =   1455
         End
         Begin VB.Label Label6 
            Caption         =   "Tipo enseñanza"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   3
            Left            =   120
            TabIndex        =   28
            Top             =   1320
            Width           =   1335
         End
         Begin VB.Label Label6 
            Caption         =   "Grado"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   4
            Left            =   120
            TabIndex        =   27
            Top             =   1800
            Width           =   615
         End
      End
      Begin VB.Frame Frame_Busqueda_Antiguos 
         Caption         =   "Alumnos Antiguos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   2775
         Left            =   120
         TabIndex        =   30
         Top             =   4800
         Width           =   6375
         Begin VB.ComboBox cmb_anho_letras 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Index           =   1
            Left            =   1680
            Style           =   2  'Dropdown List
            TabIndex        =   5
            Top             =   240
            Width           =   1335
         End
         Begin VB.Frame Frame_Sub_Nuevos 
            Caption         =   "Búsqueda de Alumnos"
            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            =   120
            TabIndex        =   31
            Top             =   840
            Width           =   6135
            Begin VB.CommandButton Btn_Limpiar 
               Caption         =   "Limpiar"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   375
               Index           =   0
               Left            =   4320
               TabIndex        =   97
               Top             =   1320
               Width           =   1575
            End
            Begin VB.ComboBox Cmb_LetCur_Ant 
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   330
               Left            =   1560
               Style           =   2  'Dropdown List
               TabIndex        =   8
               Top             =   1320
               Width           =   1095
            End
            Begin VB.CommandButton Btn_Buscar_Datos 
               Caption         =   "Buscar Datos"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   735
               Index           =   1
               Left            =   4320
               Picture         =   "Form_Letras_Principal.frx":2C75C
               Style           =   1  'Graphical
               TabIndex        =   9
               Top             =   480
               Width           =   1575
            End
            Begin VB.ComboBox Cmb_CodEns_Letras 
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   330
               Index           =   1
               Left            =   1560
               Style           =   2  'Dropdown List
               TabIndex        =   6
               Top             =   360
               Width           =   2535
            End
            Begin VB.ComboBox Cmb_NumGra_LEtras 
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   330
               Index           =   1
               Left            =   1560
               Style           =   2  'Dropdown List
               TabIndex        =   7
               Top             =   840
               Width           =   1095
            End
            Begin VB.Label Label6 
               Caption         =   "Letra"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   0
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   2
               Left            =   240
               TabIndex        =   34
               Top             =   1320
               Width           =   735
            End
            Begin VB.Label Label6 
               Caption         =   "Grado"
               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            =   240
               TabIndex        =   33
               Top             =   840
               Width           =   1095
            End
            Begin VB.Label Label6 
               Caption         =   "Tipo enseñanza"
               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            =   240
               TabIndex        =   32
               Top             =   360
               Width           =   1215
            End
         End
         Begin VB.Label Label3 
            Caption         =   "Año Escolar"
            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        =   35
            Top             =   360
            Width           =   975
         End
      End
   End
End
Attribute VB_Name = "Form_Letras_Principal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean
Dim ACodens() As Variant
Dim Sql1 As String, SqlFechaBus As String
Dim SqlCodEns As String, SqlNumGra As String
Dim ConHermanos As Boolean
Dim Agnoletra As String, CodColegioLetra As String
Dim ApoTitular As Boolean
Dim FilaLetraRep As Long, FilaLetra As Long
Dim Verde As Integer

Private Sub Btn_CartasVal_Click()
    Dim i As Integer
    conn.Execute "delete from tmp_aviso"
    For i = 1 To grd_alumnos.Rows - 1
        If grd_alumnos.TextMatrix(i, 6) = 1 Or grd_alumnos.TextMatrix(i, 11) = 1 Then
            creacartaaviso grd_alumnos.TextMatrix(i, 3), CStr(CInt(Me.cmb_anho_letras(1).Text + 1)), grd_alumnos.TextMatrix(i, 10)
        End If
    Next i
    If Not impcartaaviso(CStr(CInt(Me.cmb_anho_letras(1).Text + 1)), grd_alumnos.TextMatrix(1, 10)) Then
        MsgBox "Ha ocurrido un error durante la impresion, verificar la impresora", vbOKOnly
    End If
End Sub

Private Sub Btn_Contratos_Click()
    Dim i As Integer
    Dim var_sql As String
    var_sql = "update cfg set valor = 'SI' where param = 'LETRAS'"
    conn.Execute var_sql
    
    For i = 1 To grd_alumnos.Rows - 1
        If grd_alumnos.TextMatrix(i, 6) = 1 Or grd_alumnos.TextMatrix(i, 11) = 1 Then
            creacontrato grd_alumnos.TextMatrix(i, 3), CStr(CInt(Me.cmb_anho_letras(1).Text + 1)), "_____", True, grd_alumnos.TextMatrix(i, 10)
        End If
    Next i
    If Not impcontratoscurso(grd_alumnos.TextMatrix(1, 10), CStr(CInt(Me.cmb_anho_letras(1).Text + 1))) Then
        MsgBox "Ha ocurrido un error durante la impresion, verificar la impresora", vbOKOnly
    End If
    var_sql = "update cfg set valor = 'NO' where param = 'LETRAS'"
    conn.Execute var_sql
End Sub

Private Sub Btn_IndProcesar_Click()
If Me.Grd_IndAlu_Letras.TextMatrix(1, 0) <> "" Then
    If Me.txt_rut_acep <> "" And Me.txt_nom_acep <> "" And Me.txt_ape_pat_acep <> "" And Me.txt_ape_mat_acep <> "" And Me.txt_dir_acep <> "" And Me.Cmb_Comuna_Acep <> "" And Me.cmb_ciudad_acep <> "" Then
    
        Dim Rutabuscar As String
        Rutabuscar = Trim(Me.txt_rut_acep)
        If Not ValidaRut(Rutabuscar) Then
            Call validatexto(Me.txt_rut_acep, "Rut erróneo, sírvase a corregirlo")
            Exit Sub
        End If
        
        If (Not Me.Opt_IndCta_Mayor_Menor(0).Value And Not Me.Opt_IndCta_Mayor_Menor(1).Value) Then
            MsgBox ("Seleccione la carga de la cuenta [Hermano Mayor o Hermano Menor]")
            Exit Sub
        End If
        If MsgBox("Fecha de emisión es correcta : " & Me.Dtp_IndFecha_emision.Value, vbYesNo) = vbNo Then
                Me.Dtp_IndFecha_emision.SetFocus
                Exit Sub
        End If
        If Me.txt_indFolio_inicial <> "" Then
            If MsgBox("Folio es Correcto : " & Me.txt_indFolio_inicial, vbYesNo) = vbNo Then
                Me.txt_indFolio_inicial.SetFocus
                Exit Sub
            End If
        Else
            Call validatexto(Me.txt_indFolio_inicial, "Ingrese Folio Inicial")
            Exit Sub
        ' Verificar los folios
        End If
    
        'Si el apoderado no es titular debe grabarlo en la tabla fnza_letra_cab
        If Not ApoTitular Then
            conn.Execute "update matriculas_aux set rut_aceptante ='" & Me.txt_rut_acep & "' where rut_apo ='" & Me.Txt_IndRutApo_Letra & "'"
            conn.Execute "replace fnza_rut_letra(rut_letra, nombre_apo_letra, ape1_apo_letra, ape2_apo_letra, dir_apo_letra, comuna_apo_letra) values ('" & Me.txt_rut_acep & "','" & Me.txt_nom_acep & "','" & Me.txt_ape_pat_acep & "','" & Me.txt_ape_mat_acep & "','" & Me.txt_dir_acep & "','" & Me.cmb_codgeo_acep & "')"
        End If
        'Genero las letras, guardándolas en la tabla fnza_letras_cab
        'Las paso a pantalla para imprimirlas
        If Me.Lst_Indtipoalu_letras.Selected(0) Then
            Call Procesa(Me.Cmb_IndAnho_Letras, IIf(Opt_IndCta_Mayor_Menor(0).Value, False, True), val(Me.txt_indFolio_inicial) - 1, Me.Dtp_IndFecha_emision) ' Llamo a proceso de letras
        Else
            'Mando a procesar sin recalcular valores
            Dim RangoIni As Long, RangoFin As Long
            RangoIni = val(Me.txt_indFolio_inicial): RangoFin = val(RangoIni) + 2
            'Si hay folios ocupados en el rango proyectado
            If Not ExistReg("fnza_letra_cab", "folio_fisico >=" & RangoIni + 1 & " and folio_fisico <=" & RangoFin, conn) Then
                FilaLetra = 0: FilaLetraRep = 0
                Dim RsFuncion As ADODB.Recordset
                Dim Ralu As String, Nalu As String
                'Traemos alumno mayor
                Set RsFuncion = New ADODB.Recordset
                RsFuncion.CursorLocation = adUseClient
                sqllet2 = "select p.ci_alu, concat(p.nom_alu,' ', p.ape_pat_alu, ' ',p.ape_mat_alu) as nom_alu, c.ord_ens, m.num_gra, p.fec_nacalu, p.ci_alu from postulantes p, apo_x_alu aa, matriculas m, codigos_ensenanza c where aa.ci_alu=p.ci_alu and p.ci_alu = m.ci_alu and m.cod_ens=c.cod_ens and aa.rut_apo = '" & Me.Txt_IndRutApo_Letra & "' and m.anno_mat ='" & Me.Cmb_IndAnho_Letras & "' and ucase(m.activo_alu) ='SI' and aa.agno = m.anno_mat " & _
                          " AND ind_cup = '1' order by c.ord_ens DESC, m.num_gra DESC, p.fec_nacalu limit 1"
                RsFuncion.Open sqllet2, conn
                    If RsFuncion.RecordCount > 0 Then
                        Ralu = RsFuncion!ci_alu
                        Nalu = RsFuncion!Nom_Alu
                    End If
                RsFuncion.Close
                Call GeneraLetras(str(Me.Dtp_IndFecha_emision), val(Me.txt_indFolio_inicial) - 1, Me.txt_rut_acep, Me.Txt_IndRutApo_Letra, Me.txt_nom_acep & " " & Me.txt_ape_pat_acep & " " & Me.txt_ape_mat_acep, Me.txt_dir_acep, Me.Cmb_Comuna_Acep.Text, Me.cmb_ciudad_acep.Text, Me.Cmb_IndAnho_Letras, Ralu, Nalu)
            Else
                MsgBox ("Folio No permitido ya que se encuentra en sistema")
            End If
    
        End If
    Else
        MsgBox ("Faltan Completar campos esenciales para la emisión")
    End If
Else
    MsgBox ("No Existen Alumnos para el apoderado" & Chr(13) & "Imposible Generar Letras")
End If
End Sub

Private Sub Btn_IndSalir_Click()
Unload Me
End Sub

Private Sub Btn_Limpiar_Click(Index As Integer)
Unload Me
Menuletras = "masivo"
Load Form_Letras_Principal
End Sub

Private Sub Btn_Menu_Letras_Salir_Click()
Unload Me
End Sub

Private Sub btn_otro_apod_Click()
Unload Me
Menuletras = "individual"
Load Form_Letras_Principal
End Sub

Private Sub Btn_Procesar_Click()
If val(Trim(Lbl_Reg_Encontrados.Caption)) > 0 Then
    If (Not Me.Opt_Cta_Mayor_Menor(0).Value And Not Me.Opt_Cta_Mayor_Menor(1).Value) Then
        MsgBox ("Seleccione la carga de la cuenta [Hermano Mayor o Hermano Menor]")
        Exit Sub
    End If
    If Me.txt_folio_inicial <> "" Then
        If MsgBox("Folio " & Me.txt_folio_inicial & " es Correcto", vbYesNo) = vbNo Then
            Me.txt_folio_inicial.SetFocus
            Exit Sub
        End If
    Else
        Call validatexto(Me.txt_folio_inicial, "Ingrese Folio Inicial")
        Exit Sub
    ' Verificar los folios
    End If
    If MsgBox("Fecha de emisión es correcta : " & Me.Dtp_Fecha_Emision, vbYesNo) = vbNo Then
            Me.Dtp_Fecha_Emision.SetFocus
            Exit Sub
    End If
    If Me.Opt_Menu_Letras(0).Value Then ' Si el proceso es de alumnos nuevos
        Call Procesa(Agnoletra, IIf(Opt_Cta_Mayor_Menor(0).Value, False, True), val(Me.txt_folio_inicial) - 1, Me.Dtp_Fecha_Emision) ' Llamo a proceso de letras
    Else 'Si el proceso es de alumnos antiguos
        Call ProcesaAntiguos(Agnoletra + 1, IIf(Opt_Cta_Mayor_Menor(0).Value, False, True), val(Me.txt_folio_inicial) - 1, Me.Dtp_Fecha_Emision) ' Llamo a proceso de letras antiguos
    End If
Else
    MsgBox ("No hay apoderados para procesar")
End If
End Sub

Private Sub Btn_Buscar_Datos_Click(Index As Integer)
Dim SqlMasivo As String
Dim RegMatAux As Integer
Dim swmas As Boolean
Dim rs As ADODB.Recordset
Dim RsDa As ADODB.Recordset
'Dim Verde As Integer
Set rs = New ADODB.Recordset
Set RsDa = New ADODB.Recordset
swmas = True
grd_alumnos.Rows = 1
'Actualizar fechabus



    If Opt_Tipo_Fecha(0).Value Then
        'Fecha de Postulación
        SqlFechaBus = " and po.fec_pos "
    Else
        ' Fecha de Evaluación
        SqlFechaBus = " and date_format(po.vii_hor_eval,'%Y-%m-%d') "
    End If

If Me.cmb_anho_letras(Index) <> "" And Me.Cmb_CodEns_Letras(Index) <> "" And Me.Cmb_NumGra_LEtras(Index) <> "" Then
    Agnoletra = Me.cmb_anho_letras(Index)
    Select Case Index
        Case 0
            '#************ALUMNOS NUEVOS***************
            'Crear tabla de matrículas auxiliar e insertar datos de 2 consultas unidas
            'Consulta 1 trae todos los postulantes sin matricular
            'Consulta 2 trae todos los postulantes nuevos matriculados que tengan tipo pago cuponera
            If (Me.Opt_Tipo_Fecha(0).Value Or Me.Opt_Tipo_Fecha(1).Value) And Me.Cmb_FechaBus_Nuevos <> "" Then
                SqlFechaBus = IIf(Me.Cmb_FechaBus_Nuevos = "<Todos>", "", SqlFechaBus & "='" & Format(Me.Cmb_FechaBus_Nuevos, "yyyy-mm-dd") & "'")
                
                If Me.Cmb_CodEns_Letras(Index) = "<Todos>" Then
                    SqlCodEns = ""
                Else
                    SqlCodEns = " and p.cod_ens ='" & ACodens(Me.Cmb_CodEns_Letras(Index).ListIndex - 1) & "'"
                End If
                                
                If Me.Cmb_NumGra_LEtras(Index) = "<Todos>" Then
                    SqlNumGra = ""
                Else
                    SqlNumGra = " and p.num_gra ='" & Me.Cmb_NumGra_LEtras(Index) & "'"
                End If
                Select Case Me.Cmb_IndTipoAluNew_Mas.ListIndex
                    Case 0
                        SqlMasivo = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                        "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3) " & _
                        "(Select a.rut_apo, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & Agnoletra & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                        "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                        "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & Agnoletra & "' as anhomat, '0' as indcheq, " & _
                        "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                        "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3 " & _
                        "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                        "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.rut_apo=a.rut_apo and a.comuna_apo=cg.cod_geo and " & _
                               "p.cod_ens=c.cod_ens " & SqlCodEns & " " & SqlNumGra & " and po.anno_pos_alu='" & Agnoletra & "' " & SqlFechaBus & " and ucase(po.viii_sit_fin_alu)='A' and " & _
                               "p.ci_alu not in (select ci_alu from matriculas where anno_mat='" & Agnoletra & "' and ucase(activo_alu)='SI') " & _
                        "order by a.rut_apo, p.ci_alu)"
                    Case 1
                        SqlMasivo = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                        "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3) " & _
                        "(Select a.rut_apo, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & Agnoletra & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                        "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                        "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & Agnoletra & "' as anhomat, '0' as indcheq, " & _
                        "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                        "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3 " & _
                        "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                        "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.rut_apo=a.rut_apo and a.comuna_apo=cg.cod_geo and " & _
                               "p.cod_ens=c.cod_ens " & SqlCodEns & " " & SqlNumGra & " and po.anno_pos_alu='" & Agnoletra & "' " & SqlFechaBus & " and ucase(po.viii_sit_fin_alu)='A' and " & _
                               "p.ci_alu in (select ci_alu from matriculas where anno_mat='" & Agnoletra & "' and ucase(activo_alu)='SI' and ind_cup='1') " & _
                        "order by a.rut_apo, p.ci_alu)"
                    
                    Case 2
                        SqlMasivo = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                        "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3) " & _
                        "(Select a.rut_apo, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & Agnoletra & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                        "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                        "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & Agnoletra & "' as anhomat, '0' as indcheq, " & _
                        "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                        "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3 " & _
                        "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                        "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.rut_apo=a.rut_apo and a.comuna_apo=cg.cod_geo and " & _
                               "p.cod_ens=c.cod_ens " & SqlCodEns & " " & SqlNumGra & " and po.anno_pos_alu='" & Agnoletra & "' " & SqlFechaBus & " and ucase(po.viii_sit_fin_alu)='A' and " & _
                               "p.ci_alu not in (select ci_alu from matriculas where anno_mat='" & Agnoletra & "' and ucase(activo_alu)='SI') " & _
                        "order by a.rut_apo, p.ci_alu) " & _
                        "union (Select a.rut_apo, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & Agnoletra & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                        "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                        "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & Agnoletra & "' as anhomat, '0' as indcheq, " & _
                        "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                        "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3 " & _
                        "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                        "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.rut_apo=a.rut_apo and a.comuna_apo=cg.cod_geo and " & _
                               "p.cod_ens=c.cod_ens " & SqlCodEns & " " & SqlNumGra & " and po.anno_pos_alu='" & Agnoletra & "' " & SqlFechaBus & " and ucase(po.viii_sit_fin_alu)='A' and " & _
                               "p.ci_alu in (select ci_alu from matriculas where anno_mat='" & Agnoletra & "' and ucase(activo_alu)='SI' and ind_cup='1') " & _
                        "order by a.rut_apo, p.ci_alu)"
                
                End Select
                
                ' Proceso la consulta
                If TablaMatAux And swmas Then
                    conn.Execute SqlMasivo
                    'buscamos a los hermanos
                    SqlMasivo = "insert into matriculas_aux (ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                                "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3, rut_apo, noms_apo, dir_apo, comuna_apo,rut_aceptante,matri) " & _
                                "(Select m.ci_alu, m.activo_alu, m.num_mat, m.fec_mat, m.fec_retiro, m.reserva, m.cancelado, m.obs_cancelado, m.cod_ens, m.num_gra, m.destino_retiro, m.obs_retiro, m.cod_jor, m.obs_res, m.cod_sit, m.cod_obs_fin, m.ind_cup, m.anno_mat, m.ind_cheq, m.ind_pac, " & _
                                "m.ind_beca, m.ind_mbeca, m.tpago_act, m.cod_crit, m.ind_cont, m.cuota1, m.l1, m.l2, m.l3, ma.rut_apo, ma.noms_apo,ma.dir_apo,ma.comuna_apo,ma.rut_aceptante, 'SI' as matri from matriculas m, apo_x_alu axa, matriculas_aux ma where m.ci_alu = axa.ci_alu and m.activo_alu = 'SI' " & _
                                "and m.ci_alu in (select ci_alu from matriculas where anno_mat = " & Agnoletra - 1 & " and activo_alu = 'SI' and fec_retiro = '1111-11-11') and m.anno_mat = " & Agnoletra & " and axa.rut_apo = ma.rut_apo and axa.agno = m.anno_mat)"
                    conn.Execute SqlMasivo
                    RegMatAux = val(DevuelveCampo("matriculas_aux", "", "count(distinct rut_apo)", "rut_apo <>''", conn))
                    If RegMatAux > 0 Then
                        Me.Frame_Proceso.Enabled = True
                    Else
                        MsgBox ("NO SE ENCONTRARON DATOS")
                        Me.Frame_Proceso.Enabled = False
                    End If
                    Me.Lbl_Reg_Encontrados.Caption = RegMatAux
                    Me.Lbl_Reg_Encontrados.Refresh
                End If
            Else
                MsgBox ("Falta seleccionar campos")
            End If
        Case 1
            sqlstr = "select p.ci_alu, CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre_alu, CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo, concat(ac.cod_ens, ac.num_gra, ac.let_cur) as codens, a.rut_apo, a.dir_apo, cg.comuna, cg.provincia, m.reserva, m.ind_cup, m.ind_beca from postulantes as p, alu_x_cur as ac, apoderados as a, apo_x_alu as aa, matriculas as m, codigos__geograficos as cg " & _
                     " where  p.ci_alu = ac.Ci_alu And ac.activo_alu = 'SI' and fec_cam = '1111/11/11' and aa.ci_alu = p.ci_alu and aa.rut_apo = a.rut_apo and m.activo_alu = ac.activo_alu and m.ci_alu = p.ci_alu and cg.cod_geo = a.comuna_apo and m.anno_mat = " & CStr(cmb_anho_letras(Index).Text) + 1 & " and ac.agno = " & cmb_anho_letras(Index).Text & " and aa.agno = m.anno_mat"
            If Me.Cmb_CodEns_Letras(Index) <> "<Todos>" Then
                sqlstr = sqlstr & " and ac.cod_ens ='" & ACodens(Me.Cmb_CodEns_Letras(Index).ListIndex - 1) & "'"
            End If
            If Me.Cmb_NumGra_LEtras(Index) <> "<Todos>" Then
                sqlstr = sqlstr & " and ac.num_gra ='" & Me.Cmb_NumGra_LEtras(Index) & "'"
            End If
            If Me.Cmb_LetCur_Ant <> "<Todos>" Then
                sqlstr = sqlstr & " and ac.let_cur = '" & Me.Cmb_LetCur_Ant & "'"
            End If
            rs.CursorLocation = adUseClient
            sqlstr = sqlstr & " order by nombre_apo,nombre_alu"
            rs.Open sqlstr, conn
            i = 1: Verde = 0
            If rs.RecordCount > 0 Then
                While Not (rs.EOF)
                    grd_alumnos.Rows = i + 1
                    grd_alumnos.Row = i
                    grd_alumnos.TextMatrix(i, 11) = 0
                    If CInt(rs("reserva")) = 2 Then
                        For k = 0 To 6
                            grd_alumnos.Col = k
                            grd_alumnos.CellBackColor = &H8080FF
                        Next k
                        grd_alumnos.TextMatrix(i, 6) = 0
                    Else
                        If EselMayoraxc(rs("ci_alu"), CStr(CInt(cmb_anho_letras(Index).Text) + 1)) Then
                            For k = 0 To 6
                                grd_alumnos.Col = k
                                grd_alumnos.CellBackColor = &HC0FFC0
                            Next k
                            grd_alumnos.TextMatrix(i, 6) = 1
                            Verde = Verde + 1
                            Me.Lbl_Reg_Encontrados.Caption = Verde
                            Me.Lbl_Reg_Encontrados.Refresh
                        Else
                            grd_alumnos.TextMatrix(i, 6) = 0
                        End If
                        If EselMayoraxc(rs("ci_alu"), CStr(CInt(cmb_anho_letras(Index).Text) + 1)) And rs("ind_beca") = 1 Then
                           For k = 0 To 6
                                grd_alumnos.Col = k
                                grd_alumnos.CellBackColor = &HC0FFFF
                           Next k
                           grd_alumnos.TextMatrix(i, 11) = 1
                        End If
                    End If
                    'If devuelvecampo("apo_x_alu", "", "cambio_apo", "ci_alu='" & Rs("ci_alu") & "'", conn) = "SI" Then
                        
                    grd_alumnos.TextMatrix(i, 0) = rs("nombre_apo")
                    grd_alumnos.TextMatrix(i, 1) = rs("ci_alu")
                    grd_alumnos.TextMatrix(i, 2) = rs("nombre_alu")
                    grd_alumnos.TextMatrix(i, 3) = rs("rut_apo")
                    grd_alumnos.TextMatrix(i, 4) = rs("dir_apo")
                    grd_alumnos.TextMatrix(i, 5) = rs("comuna")
                    grd_alumnos.TextMatrix(i, 7) = rs("ind_cup")
                    grd_alumnos.TextMatrix(i, 8) = IIf(rs("ind_beca") = 1, "100", "0")
                    grd_alumnos.TextMatrix(i, 9) = rs("provincia")
                    grd_alumnos.TextMatrix(i, 10) = rs("codens")
                    i = i + 1
                    rs.MoveNext
                Wend
                
                
            End If
            If Verde > 0 Then
                Me.Frame_Proceso.Enabled = True
            Else
                MsgBox ("Faltan seleccionar campos")
                Me.Frame_Proceso.Enabled = False
            End If
            grd_alumnos.Row = 0
            swmas = False
    
    End Select

    'Traer_Alumnos , Cargar_Mat_Aux
    'Recorrer mat_aux, calcular_mensualidades
    'Llenar_tabla_letras , Llenar_Grilla_pre_impresión
    
Else
    MsgBox ("Falta seleccionar campos")
End If

If Verde > 0 Then
    Btn_Contratos.Enabled = True
    Btn_Procesar.Enabled = True
End If

End Sub


Private Sub Chk_titular_letras_Click()
ApoTitular = IIf(Me.Chk_titular_letras.Value = 1, True, False)
Call Datostitular(Me.Chk_titular_letras.Value)
Me.Frame_Aceptante_Letras.Enabled = IIf(Me.Chk_titular_letras.Value = 1, False, True)
End Sub

Private Sub cmb_anho_letras_Click(Index As Integer)
Select Case Index
    Case 0 ' Alumnos Nuevos
        Me.Opt_Tipo_Fecha(0).Value = False
        Me.Opt_Tipo_Fecha(1).Value = False
        Me.Cmb_FechaBus_Nuevos.Clear
    Case 1

End Select
End Sub

Private Sub Cmb_CodEns_Letras_Click(Index As Integer)
Dim t As Integer, nivel As Integer
If Me.Cmb_CodEns_Letras(Index) <> "" Then
    If Me.Cmb_CodEns_Letras(Index) = "<Todos>" Then
        Me.Cmb_NumGra_LEtras(Index).Clear
        Me.Cmb_NumGra_LEtras(Index).AddItem "<Todos>"
    Else
        nivel = DevuelveCampo("codigos_ensenanza", "", "num_gra_max", "cod_ens = '" & ACodens(Me.Cmb_CodEns_Letras(Index).ListIndex - 1) & "'", conn)
        Me.Cmb_NumGra_LEtras(Index).Clear
        Me.Cmb_NumGra_LEtras(Index).AddItem "<Todos>"
        For t = 1 To val(nivel)
            Me.Cmb_NumGra_LEtras(Index).AddItem t
        Next t
    End If
    'Btn_Contratos.Enabled = False
    'Btn_CartasVal.Enabled = False
End If
End Sub


Private Sub Cmb_Comuna_Acep_Click()
Me.cmb_ciudad_acep.ListIndex = Me.Cmb_Comuna_Acep.ListIndex
Me.cmb_codgeo_acep.ListIndex = Me.cmb_ciudad_acep.ListIndex
End Sub



Private Sub Cmb_IndAnho_Letras_Click()
'Me.cmb_indtipoalu_letras.ListIndex = -1
End Sub

Private Sub cmb_indcolegio_letras_Click()
'Me.cmb_indtipoalu_letras.ListIndex = -1
Call Inigrillaalu
End Sub


Private Sub Cmb_LetCur_Ant_Click()
    'If Cmb_LetCur_Ant.Text <> "<Todos>" Then
      '  Btn_Contratos.Enabled = True
      '  Btn_CartasVal.Enabled = True
    'End If
End Sub

Private Sub Cmb_NumGra_LEtras_Click(Index As Integer)
Dim agno As Integer

If Index = 1 Then
    Me.Cmb_LetCur_Ant.Clear
    Me.Cmb_LetCur_Ant.AddItem "<Todos>"
    Ngrado = Me.Cmb_NumGra_LEtras(Index).Text
    agno = cmb_anho_letras(Index).Text
    CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_CodEns_Letras(Index).Text & "'", conn)
    Call LlenaCombo(Me.Cmb_LetCur_Ant, "cursos", "let_cur", "where cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and agno = " & agno, conn)
    Btn_Contratos.Enabled = False
    Btn_CartasVal.Enabled = False
End If
End Sub

Private Sub Form_Load()
    'Me.Height = 8160
    'Me.Width = 6690
    
    
    Select Case Menuletras
        Case "individual"
            Me.Lst_IndNomApo_Letra.Visible = False
            Me.Lst_IndRutApo_Letra.Visible = False
            Flag_sub = False
            Me.Frame_Masivo_Letras.Visible = False
            Me.Frame_Individual_Letras.Top = 120
            Me.Frame_Individual_Letras.Left = 120
            Me.Frame_Individual_Letras.Visible = True
            Call LlenaComboAgno
            Me.Width = 14010
            'Call LlenaTipoAlu
            Call LlenaComunas
            Call Inigrillaalu
            Call llenacomboconarreglo(Cmb_Indcolegio_letras, "hist_cod_colegio h, establecimientos e where length(h.colegio)=6 and h.cod_rbd=e.rdb", "nombre", "h.colegio", AColegios, conn)
            Me.Cmb_Indcolegio_letras.ListIndex = 0
            Me.Dtp_IndFecha_emision.Value = Date
        Case "masivo"
            Me.Frame_Individual_Letras.Visible = False
            Me.Frame_Masivo_Letras.Top = 0
            Me.Frame_Masivo_Letras.Left = 0
            Me.Frame_Masivo_Letras.Visible = True
            Call llenacomboconarreglo(Cmb_Colegio_Letras, "hist_cod_colegio h, establecimientos e where length(h.colegio)=6 and h.cod_rbd=e.rdb", "nombre", "h.colegio", AColegios, conn)
            Me.Cmb_Colegio_Letras.ListIndex = 0
            Me.Dtp_IndFecha_emision.Value = Date
            Me.Frame_Proceso.Enabled = False
            'Me.Height = 8110
            Me.Width = 6690
            Me.Show
            Me.Dtp_Fecha_Emision.Value = Date
    End Select
    
    CodColegioLetra = AColegios(0)
    
End Sub


Private Sub Form_Unload(Cancel As Integer)
Call menuhabilitado(True)
End Sub












Private Sub Lst_IndNomApo_Letra_DblClick()
Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Me.Txt_IndNomApo_Letra.Text = Me.Lst_IndNomApo_Letra.Text
    Me.Lst_IndNomApo_Letra.Visible = False
    Me.Lst_IndRutApo_Letra.Visible = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT a.rut_apo, a.dir_apo, c.comuna, c.provincia FROM apoderados a, codigos__geograficos c where a.comuna_apo=c.cod_geo and left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(Me.Txt_IndNomApo_Letra.Text) & ")='" & Me.Txt_IndNomApo_Letra.Text & "' ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        Flag_sub = True
        Me.Txt_IndNomApo_Letra.Locked = True
        Me.Txt_IndRutApo_Letra.Locked = True
        Me.Txt_IndRutApo_Letra.Text = rs!rut_apo
        Me.txt_dirapo_Letra = rs!dir_apo
        Me.txt_comunaapo_letra = rs!Comuna
        Me.txt_ciudadapo_letra = rs!provincia
    End If
    Flag_sub = True
    rs.Close
    Set rs = Nothing
    Call LlenaColegios
    Me.Chk_titular_letras.Value = 1
End Sub

Private Sub Lst_IndRutApo_Letra_DblClick()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Me.Txt_IndRutApo_Letra = Me.Lst_IndRutApo_Letra.Text
    Me.Lst_IndRutApo_Letra.Visible = False
    Me.Lst_IndNomApo_Letra.Visible = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT a.dir_apo, c.comuna, c.provincia, CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo) as nombre_apo FROM apoderados a, codigos__geograficos c where a.comuna_apo=c.cod_geo and a.rut_apo='" & Me.Txt_IndRutApo_Letra.Text & "' ORDER BY a.rut_apo;", conn
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        Flag_sub = True
        Me.Txt_IndNomApo_Letra.Text = rs!nombre_apo
        Me.txt_dirapo_Letra = rs!dir_apo
        Me.txt_comunaapo_letra = rs!Comuna
        Me.txt_ciudadapo_letra = rs!provincia
    End If
    Flag_sub = True
    rs.Close
    Set rs = Nothing
    Me.Chk_titular_letras.Value = 1
End Sub

Private Sub Lst_Indtipoalu_letras_Click()
Me.Lst_Indtipoalu_letras.Selected(0) = False
If Me.Cmb_IndAnho_Letras <> "" Then
    Call MatriculaAux(Me.Txt_IndRutApo_Letra, Me.txt_rut_acep, Me.Cmb_IndAnho_Letras, CodColegioLetra, Me.Lst_Indtipoalu_letras)
    Call LlenaGrilla(Me.Grd_IndAlu_Letras, "Rut Alumno, Codens   , Nivel  ,   Rut Apod., Año Mat.  ,Matriculado ", "matriculas_aux", "ci_alu; cod_ens; num_gra; rut_apo; anno_mat; MATRI", "ci_alu <>'' order by cod_ens desc, num_gra desc, ci_alu", conn)
Else
    MsgBox ("Seleccione año")
    Me.Cmb_IndAnho_Letras.SetFocus
End If
End Sub

Private Sub Opt_Menu_Letras_Click(Index As Integer)
    Call Esconder_Frames
    Select Case Index
    Case 0 ' Alumnos Nuevos
        AluNuevos = True
        Me.Frame_Busqueda_Nuevos.Visible = True
        Me.Frame_Busqueda_Nuevos.Top = 2160
        Me.Frame_Busqueda_Nuevos.Left = 120
        Me.Frame_muestraalumnos.Visible = False
        Me.Width = 14010
        Me.Cmb_IndTipoAluNew_Mas.Clear
        Me.Cmb_IndTipoAluNew_Mas.AddItem "Aceptados"
        Me.Cmb_IndTipoAluNew_Mas.AddItem "Matriculados"
        Me.Cmb_IndTipoAluNew_Mas.AddItem "Ambos"
       ' Me.Height = 7260
    Case 1 ' Alumnos Antiguos
        AluNuevos = False
        Me.Frame_Busqueda_Antiguos.Visible = True
        Me.Frame_Busqueda_Antiguos.Top = 2160
        Me.Frame_Busqueda_Antiguos.Left = 120
        Me.Frame_muestraalumnos.Visible = True
        Me.Width = 14010
        'Me.Height = 7350
        grd_alumnos.ColWidth(0) = 3300
        grd_alumnos.ColWidth(1) = 0
        grd_alumnos.ColWidth(2) = 3300
        grd_alumnos.ColWidth(3) = 0
        grd_alumnos.ColWidth(4) = 0
        grd_alumnos.ColWidth(5) = 0
        grd_alumnos.ColWidth(6) = 0
        grd_alumnos.ColWidth(7) = 0
        grd_alumnos.ColWidth(8) = 0
        grd_alumnos.ColWidth(9) = 0
        grd_alumnos.ColWidth(10) = 0
        grd_alumnos.ColWidth(11) = 0
        grd_alumnos.ColAlignment(0) = 1
        grd_alumnos.ColAlignment(1) = 1
        grd_alumnos.ColAlignment(2) = 1
        grd_alumnos.ColAlignment(3) = 1
        grd_alumnos.ColAlignment(4) = 1
        grd_alumnos.ColAlignment(5) = 1
        grd_alumnos.ColAlignment(6) = 1
        grd_alumnos.ColAlignment(7) = 1
        grd_alumnos.ColAlignment(8) = 1
        Me.Frame_muestraalumnos.Visible = True
    End Select
    Me.cmb_anho_letras(Index).Clear
    Me.cmb_anho_letras(Index).AddItem Year(Date) - 1
    Me.cmb_anho_letras(Index).AddItem Year(Date)
    Me.cmb_anho_letras(Index).AddItem Year(Date) + 1
    
    Me.cmb_anho_letras(Index).ListIndex = 0
    
    Me.Cmb_CodEns_Letras(Index).Clear
    Me.Cmb_CodEns_Letras(Index).AddItem "<Todos>"
    Call llenacomboconarreglo(Me.Cmb_CodEns_Letras(Index), "codigos_ensenanza order by ord_ens", "des_ens", "cod_ens", ACodens(), conn)
End Sub

Function TablaMatAux() As Boolean
On Error GoTo controlerr
conn.Execute "DROP TABLE IF EXISTS MATRICULAS_AUX;"
'Crear tabla auxiliar de matriculas
conn.Execute "CREATE TABLE `MATRICULAS_AUX` TYPE=MyISAM SELECT * FROM MATRICULAS WHERE CI_ALU='NINGUNOX'"
'Agrego campo rut apoderado, para cálculo de mensualidad posteriormente
conn.Execute "ALTER TABLE `MATRICULAS_AUX` ADD `RUT_APO` VARCHAR(10), " & _
             "ADD `NOMS_APO` VARCHAR(70), " & _
             "ADD `DIR_APO` VARCHAR(40), " & _
             "ADD `COMUNA_APO` VARCHAR(10), " & _
             "ADD `RUT_ACEPTANTE` VARCHAR(10), " & _
             "ADD `MATRI` VARCHAR(2)"
Set RsFuncion = New ADODB.Recordset
RsFuncion.CursorLocation = adUseClient
RsFuncion.Open "select * from matriculas_aux", conn
TablaMatAux = True
RsFuncion.Close
Set RsFuncion = Nothing
Exit Function
controlerr:
Set RsFuncion = Nothing
TablaMatAux = False
    errnum = Err.Number
    errdes = Err.Description
    errsou = Err.Source
    Err.Raise errnum, errsou & vbCrLf & "Form_Letras_Principal.TablaMataux", errdes
    Resume
End Function
Sub Esconder_Frames()
Me.Frame_Busqueda_Antiguos.Visible = False
Me.Frame_Busqueda_Nuevos.Visible = False
End Sub
Sub Procesa(Agnoletraproc As String, MayorProc As Boolean, FolioLetraNew As Long, Fecha_emision As String)
    Dim Rutapod As String
    Dim Rut_acep_letra As String
    Dim aalumnos As Variant
    Dim Rut_Alumno_Titular As String, Nom_alumno_titular As String
    Dim TotalMes As Long
    Dim Mayor As Boolean
    Dim Letra1 As Long, letra2 As Long, Letra3 As Long
    Dim FolioInternoLetra As String
    Dim ClaveLetra As String
    Dim Encontro As Boolean
    Dim Abarra As Integer
    Dim RangoIni As Long, RangoFin As Long
    Dim RsFuncionLetras As ADODB.Recordset
    Set RsFuncionLetras = New ADODB.Recordset
    Dim RsVerifLetras As ADODB.Recordset
    Dim Femis_Letra As String
    Dim ValorDetalle As Long
    Femis_Letra = Format(Fecha_emision, "yyyy/mm/dd")
    
    RsFuncionLetras.CursorLocation = adUseClient
    
    ' Tengo el rut del apoderado en la tabla de matriculas auxiliar por lo tanto
    ' La Funcion CuotaAlumnosApoFecha me trae los alumnos ordenados de > a <
    ' según selección.
    
    'Determinar el orden
    RsFuncionLetras.Open "select distinct m.rut_aceptante, m.rut_apo, m.noms_apo, m.dir_apo, c.provincia, c.comuna from matriculas_aux m, codigos__geograficos c where m.comuna_apo=c.cod_geo order by m.cod_ens, m.num_gra, m.cod_jor", conn
    FilaLetra = 0: FilaLetraRep = 0
    If RsFuncionLetras.RecordCount > 0 Then
        RsFuncionLetras.MoveFirst
        Form_Progress.Label1.Caption = "Generando Letras ..."
        Form_Progress.Show
        Form_Progress.ProgBar1.MaxValue = RsFuncionLetras.RecordCount - 1
        RangoIni = val(FolioLetraNew): RangoFin = val(RangoIni + (RsFuncionLetras.RecordCount) * 3)
        'Si hay folios ocupados en el rango proyectado
        If Not ExistReg("fnza_letra_cab", "folio_fisico >=" & RangoIni + 1 & " and folio_fisico <=" & RangoFin, conn) Then
            
            For t = 0 To RsFuncionLetras.RecordCount - 1
                Rut_acep_letra = RsFuncionLetras!rut_aceptante
                '********Función trae alumnos según tabla MATRICULAS_AUX**********
                'SI EL ALUMNO NO ESTÁ MATRICULADO REALMENTE LE CALCULO LA MENSUALIDAD
                    aalumnos = CuotaAlumnosApoFecha(RsFuncionLetras!rut_apo, Agnoletraproc, 3, conn)
                    ' El array viene con almnos ordenados de mayor a menor
                    Encontro = False
                    If UBound(aalumnos, 2) >= 1 Then
                        TotalMes = 0
                        For i = 1 To UBound(aalumnos, 2)
                            'If (Particular = "SI" And Len(aalumnos(9, i)) = 9) Or (Particular = "NO" And Len(aalumnos(9, i)) = 6) Then
                                Encontro = True
                                If aalumnos(11, i) = 1 Then ' Si paga con Cuponera
                                    resp7 = aalumnos(7, i)
                                    TotalMes = TotalMes + resp7
                                    If MayorProc Then
                                        Rut_Alumno_Titular = aalumnos(1, 1)
                                        Nom_alumno_titular = aalumnos(10, 1)
                                    Else
                                        Rut_Alumno_Titular = aalumnos(1, UBound(aalumnos, 2))
                                        Nom_alumno_titular = aalumnos(10, UBound(aalumnos, 2))
                                    End If
                                End If
                            'End If
                        Next i
'                    End If
                    If Encontro Then
                    
                        'Tengo el total del mes del apoderado
                        'Lo trabajo
                        '****************Proc. Temporal******************
                        '*****Crear función para calcular las letras*****
                        ValorContrato = TotalMes * 11
                        Letra1 = TotalMes * 4 'Marzo Abril Mayo Junio
                        letra2 = TotalMes * 3 'Julio Agosto Septiembre
                        Letra3 = TotalMes * 3 'Octubre Noviembre Diciembre
                    
                        'VERIFICAR SI LETRA1 NO EXISTE EN SISTEMA
                        Set RsVerifLetras = New ADODB.Recordset
                        RsVerifLetras.CursorLocation = adUseClient
    
                        RsVerifLetras.Open "(select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, " & _
                        "f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, " & _
                        "f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, " & _
                        "concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':', " & _
                        "f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and f.agno = aa.agno " & _
                        "and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and " & _
                        "f.fecha_letra ='" & Agnoletraproc & "-06-10' and f.estado_letra <>'A' " & _
                        ") " & _
                        "Union " & _
                        "( " & _
                        "select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, " & _
                        "concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, " & _
                        "f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, " & _
                        "concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as " & _
                        "nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and f.agno = aa.agno and " & _
                        "f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and " & _
                        "f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and f.fecha_letra ='" & Agnoletraproc & "-06-10' and f.estado_letra <>'A')", conn
        
                        
                        If RsVerifLetras.RecordCount > 0 Then
                            FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 1, 3, RsVerifLetras!folio_interno, RsVerifLetras!Fecha_emision, CodColegioLetra)
                            'FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, folioletranew, Rut_Acep_Letra, RsFuncionLetras!noms_apo, AgnoletraProc & "-06-10", 3, 6, AgnoletraProc, Letra1, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_Alumno_Titular, RsFuncionLetras!rut_apo, RsFuncionLetras!noms_apo, ClaveLetra)
                        Else
                            'Guardo en tabla letras, la letra1
                            FilaLetra = FilaLetra + 1
                            FolioLetraNew = FolioLetraNew + 1
                            'conn.Execute "insert into fnza_letra_cab (Folio_fisico, agno, colegio, rut_aceptante, fecha_letra, monto_letra, run_alu, run_apo, periodo_ini, periodo_fin, fecha_emision, estado_letra, factoring) " & _
                            '"values (" & folioletranew & " ,'" & Agnoletraproc & "','" & CodColegioLetra & "','" & Rut_Acep_Letra & "','" & Agnoletraproc & "-06-10'," & Letra1 & ",'" & Rut_Alumno_Titular & "','" & RsFuncionLetras!Rut_apo & "',3,6,'" & Format(Me.Dtp_Fecha_Emision.Value, "yyyy/mm/dd") & "','V','N')"
                            'FolioInternoLetra = CStr(devuelvecampo("fnza_letra_cab", "", "folio_interno", "colegio ='" & CodColegioLetra & "' and agno =" & Agnoletraproc & " and rut_aceptante ='" & Rut_Acep_Letra & "' and fecha_letra ='" & Agnoletraproc & "-06-10' and ucase(estado_letra) ='V'", conn))
                            'ClaveLetra = folioletranew & "-" & FolioInternoLetra & ":" & Agnoletraproc & "-" & CodColegioLetra
                            If RsFuncionLetras!rut_apo = RsFuncionLetras!rut_aceptante Then
                                Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, RsFuncionLetras!Noms_Apo, Agnoletraproc & "-06-10", 3, 6, Agnoletraproc, Letra1, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 1, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                            Else
                                Dim NomAcep As String, DirAcep As String, ComuAcep As String, ProvAcep As String
                                NomAcep = ""
                                DirAcep = ""
                                ComuAcep = ""
                                ProvAcep = ""
                                Set rs = New ADODB.Recordset
                                rs.CursorLocation = adUseClient
                                rs.Open "select * from fnza_rut_letra f, codigos__geograficos c where f.comuna_apo_letra=c.cod_geo and f.rut_letra ='" & RsFuncionLetras!rut_aceptante & "'", conn
                                If rs.RecordCount > 0 Then
                                    NomAcep = rs!nombre_apo_letra & " " & rs!ape1_apo_letra & " " & rs!ape2_apo_letra
                                    DirAcep = rs!dir_apo_letra
                                    ComuAcep = rs!Comuna
                                    ProvAcep = rs!provincia
                                    Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, NomAcep, Agnoletraproc & "-06-10", 3, 6, Agnoletraproc, Letra1, DirAcep, ComuAcep, ProvAcep, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 1, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                                End If
                                rs.Close
                                Set rs = Nothing
                            End If
                        End If
                        RsVerifLetras.Close:
                        Set RsVerifLetras = Nothing
                        'VERIFICAR SI LETRA2 NO EXISTE EN SISTEMA
                        Set RsVerifLetras = New ADODB.Recordset
                        RsVerifLetras.CursorLocation = adUseClient

                        RsVerifLetras.Open "(select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, " & _
                        "f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, " & _
                        "f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, " & _
                        "concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':', " & _
                        "f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and aa.agno = f.agno " & _
                        "and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and " & _
                        "f.fecha_letra ='" & Agnoletraproc & "-09-10' and f.estado_letra <>'A' " & _
                        ") " & _
                        "Union " & _
                        "( " & _
                        "select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, " & _
                        "concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, " & _
                        "f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, " & _
                        "concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as " & _
                        "nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and aa.agno = f.agno and " & _
                        "f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and " & _
                        "f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and f.fecha_letra ='" & Agnoletraproc & "-09-10' and f.estado_letra <>'A')", conn
                        
                        If RsVerifLetras.RecordCount > 0 Then
                            FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 2, 3, RsVerifLetras!folio_interno, RsVerifLetras!Fecha_emision, CodColegioLetra)
                            'FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, folioletranew, Rut_Acep_Letra, RsFuncionLetras!noms_apo, AgnoletraProc & "-06-10", 3, 6, AgnoletraProc, Letra1, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_Alumno_Titular, RsFuncionLetras!rut_apo, RsFuncionLetras!noms_apo, ClaveLetra)
                        Else
                            'Guardo en tabla letras, la letra2
                            FilaLetra = FilaLetra + 1
                            FolioLetraNew = FolioLetraNew + 1
                            'conn.Execute "insert into fnza_letra_cab (Folio_fisico, agno, colegio, rut_aceptante, fecha_letra, monto_letra, run_alu, run_apo, periodo_ini, periodo_fin, fecha_emision, estado_letra, factoring) " & _
                            '"values (" & folioletranew & " ,'" & Agnoletraproc & "','" & CodColegioLetra & "','" & Rut_Acep_Letra & "','" & Agnoletraproc & "-09-10'," & Letra2 & ",'" & Rut_Alumno_Titular & "','" & RsFuncionLetras!Rut_apo & "',7,9,'" & Format(Me.Dtp_Fecha_Emision.Value, "yyyy/mm/dd") & "','V','N')"
                            'FolioInternoLetra = CStr(devuelvecampo("fnza_letra_cab", "", "folio_interno", "colegio ='" & CodColegioLetra & "' and agno =" & Agnoletraproc & " and rut_aceptante ='" & Rut_Acep_Letra & "' and fecha_letra ='" & Agnoletraproc & "-09-10' and ucase(estado_letra) ='V'", conn))
                            'ClaveLetra = folioletranew & "-" & FolioInternoLetra & ":" & Agnoletraproc & "-" & CodColegioLetra
                            If RsFuncionLetras!rut_apo = RsFuncionLetras!rut_aceptante Then
                                Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, RsFuncionLetras!Noms_Apo, Agnoletraproc & "-09-10", 7, 9, Agnoletraproc, letra2, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 2, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                            Else
                                Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, NomAcep, Agnoletraproc & "-09-10", 7, 9, Agnoletraproc, letra2, DirAcep, ComuAcep, ProvAcep, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 2, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                            End If
                        End If
                        RsVerifLetras.Close:
                        Set RsVerifLetras = Nothing
                        
                        'VERIFICAR SI LETRA3 NO EXISTE EN SISTEMA
                        Set RsVerifLetras = New ADODB.Recordset
                        RsVerifLetras.CursorLocation = adUseClient
    
                        RsVerifLetras.Open "(select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, " & _
                        "f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, " & _
                        "f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, " & _
                        "concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':', " & _
                        "f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and f.agno = aa.agno " & _
                        "and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and " & _
                        "f.fecha_letra ='" & Agnoletraproc & "-12-10' and f.estado_letra <>'A' " & _
                        ") " & _
                        "Union " & _
                        "( " & _
                        "select f.fecha_emision, f.folio_interno, f.folio_fisico, f.rut_aceptante, " & _
                        "concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, " & _
                        "f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, " & _
                        "concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as " & _
                        "nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
                        "From " & _
                        "fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p " & _
                        "Where " & _
                        "a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and f.agno = aa.agno and " & _
                        "f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and " & _
                        "f.rut_aceptante ='" & RsFuncionLetras!rut_aceptante & "' and f.fecha_letra ='" & Agnoletraproc & "-12-10' and f.estado_letra <>'A')", conn
                                
                        If RsVerifLetras.RecordCount > 0 Then
                            FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 3, 3, RsVerifLetras!folio_interno, RsVerifLetras!Fecha_emision, CodColegioLetra)
                            'FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, folioletranew, Rut_Acep_Letra, RsFuncionLetras!noms_apo, AgnoletraProc & "-06-10", 3, 6, AgnoletraProc, Letra1, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_Alumno_Titular, RsFuncionLetras!rut_apo, RsFuncionLetras!noms_apo, ClaveLetra)
                        Else
    
                            'Guardo en tabla letras, la letra3
                            FilaLetra = FilaLetra + 1
                            FolioLetraNew = FolioLetraNew + 1
                            'conn.Execute "insert into fnza_letra_cab (Folio_fisico, agno, colegio, rut_aceptante, fecha_letra, monto_letra, run_alu, run_apo, periodo_ini, periodo_fin, fecha_emision, estado_letra, factoring) " & _
                            '"values (" & folioletranew & " ,'" & Agnoletraproc & "','" & CodColegioLetra & "','" & Rut_Acep_Letra & "','" & Agnoletraproc & "-12-10'," & Letra3 & ",'" & Rut_Alumno_Titular & "','" & RsFuncionLetras!Rut_apo & "',10,12,'" & Format(Me.Dtp_Fecha_Emision.Value, "yyyy/mm/dd") & "','V','N')"
                            'FolioInternoLetra = CStr(devuelvecampo("fnza_letra_cab", "", "folio_interno", "colegio ='" & CodColegioLetra & "' and agno =" & Agnoletraproc & " and rut_aceptante ='" & Rut_Acep_Letra & "' and fecha_letra ='" & Agnoletraproc & "-12-10' and ucase(estado_letra) ='V'", conn))
                            'ClaveLetra = folioletranew & "-" & FolioInternoLetra & ":" & Agnoletraproc & "-" & CodColegioLetra
                            If RsFuncionLetras!rut_apo = RsFuncionLetras!rut_aceptante Then
                                Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, RsFuncionLetras!Noms_Apo, Agnoletraproc & "-12-10", 10, 12, Agnoletraproc, Letra3, RsFuncionLetras!dir_apo, RsFuncionLetras!Comuna, RsFuncionLetras!provincia, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 3, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                            Else
                                Call Lista_Letra(FilaLetra, FolioLetraNew, Rut_acep_letra, NomAcep, Agnoletraproc & "-12-10", 10, 12, Agnoletraproc, Letra3, DirAcep, ComuAcep, ProvAcep, Rut_Alumno_Titular, Nom_alumno_titular, RsFuncionLetras!rut_apo, RsFuncionLetras!Noms_Apo, ClaveLetra, 3, 3, FolioInternoLetra, Femis_Letra, CodColegioLetra)
                            End If
                        End If
                        RsVerifLetras.Close:
                        Set RsVerifLetras = Nothing
                        '****************Proc. Temporal******************
                    End If
                End If
                RsFuncionLetras.MoveNext
                Form_Progress.ProgBar1.ShowProgress t
                DoEvents
            Next t
        
        Else
            MsgBox ("Folio No permitido ya que se encuentra en sistema")
        End If
    End If
    RsFuncionLetras.Close
    Set RsFuncionLetras = Nothing
    Unload Form_Progress
End Sub

Sub Lista_Letra(ByRef FilaLet As Long, Folio As Long, RutAcept As String, NomAcept As String, Vencim As String, Mes_Ini As Integer, Mes_Fin As Integer, agno As String, valor As Long, Domicilio As String, Comuna As String, Ciudad As String, rutalumno As String, NomAlumno As String, Rutapod As String, NomApod As String, Clave As String, X As Integer, De As Integer, Folioint As String, fec_emis As String, CodColegio As String)
    Form_Letras_Datos.Grd_Datos_Letras.AddItem ""
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 0) = FilaLet
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 1) = Folio
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 2) = RutAcept
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 3) = NomAcept
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 4) = Vencim
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 5) = MesATexto(Mes_Ini)
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 6) = MesATexto(Mes_Fin)
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 7) = agno
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 8) = valor
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 9) = Domicilio
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 10) = Comuna
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 11) = Ciudad
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 12) = rutalumno
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 13) = NomAlumno
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 14) = Rutapod
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 15) = NomApod
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 16) = Clave
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 17) = X
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 18) = De
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 19) = Folioint
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 20) = Mes_Ini
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 21) = Mes_Fin
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 22) = fec_emis
    Form_Letras_Datos.Grd_Datos_Letras.TextMatrix(FilaLet, 23) = CodColegio
    Form_Letras_Datos.Refresh

End Sub

'Esta función trabaja con una tabla de matrícula auxiliar
Private Function CuotaAlumnosApoFecha(ByVal RunApo As String, ByVal agno As Integer, ByVal mes As Integer, ByRef CNX As ADODB.Connection) As Variant
Dim errnum As Double
Dim errdes As String
Dim errsou As String
'On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    Dim ValAlumnos() As Variant
    Dim swBeca As Boolean
    Dim PorcentajeTipoPago As Integer
    
    swBeca = False
    PorcentajeTipoPago = 0
    ReDim Preserve ValAlumnos(1 To 11, 1 To 1)
    ValAlumnos(1, 1) = ""   'Run Alumno
    ValAlumnos(2, 1) = 0    'Arancel Base
    ValAlumnos(3, 1) = 0    'Descuento Beca
    ValAlumnos(4, 1) = 0    'Descuento Hermano
    ValAlumnos(5, 1) = 0    'Descuento Ajuste Especial
    ValAlumnos(6, 1) = 0    'Descuento Convenio
    ValAlumnos(10, 1) = 0   'Descuento Tipo Pago
    ValAlumnos(7, 1) = 0    'Total a Pagar
    ValAlumnos(8, 1) = ""   'Codigo Convenio
    ValAlumnos(9, 1) = ""   'Codigo Colegio
    ValAlumnos(10, 1) = ""  'Nombre del Alumno
    ValAlumnos(11, 1) = ""  'Cuponera
    'QR = "SELECT alu.*, fd.convenio1, fd.hermanos, fd.arancel_base FROM fnza_descuento as fd, (SELECT axa.rut_apo, axa.ci_alu, m.fec_mat, m.fec_retiro, if(m.cod_ens='996',concat(c.colegio,'MMC'),c.colegio) as cole, concat(m.cod_ens, m.num_gra) as curso, m.cod_ens, m.anno_mat, m.ind_beca, m.ind_mbeca, m.ind_cheq, m.ind_cont, p.fec_nacalu, a.cod_conv FROM apo_x_alu as axa, MATRICULAS_AUX as m, postulantes as p, apoderados as a, (SELECT cc.colegio FROM hist_cod_colegio as cc, establecimientos as e WHERE e.rdb=cc.cod_rbd) as c WHERE axa.rut_apo='" & RunApo & "' AND axa.ci_alu=m.ci_alu AND m.anno_mat='" & Agno & "' AND m.fec_mat<='" & Agno & "-" & Format(Mes, "00") & "-15' AND (m.fec_retiro='1111-11-11' OR m.fec_retiro>'" & Agno & "-" & Format(Mes, "00") & "-15') AND p.ci_alu=axa.ci_alu AND axa.rut_apo=a.rut_apo ) as alu WHERE fd.colegio=alu.cole AND fd.curso=alu.curso AND fd.agno=alu.anno_mat ORDER BY alu.cole, alu.curso DESC, alu.fec_nacalu, alu.ci_alu;"
    
    'En esta consulta se agrega el nombre del alumno
    QR = "SELECT alu.*, fd.convenio1, fd.hermanos, fd.arancel_base FROM fnza_descuento as fd, (SELECT axa.rut_apo, axa.ci_alu, m.fec_mat, m.fec_retiro, if(m.cod_ens='996',concat(c.colegio,'MMC'),c.colegio) as cole," & _
    " concat(m.cod_ens, m.num_gra) as curso, m.cod_ens, m.anno_mat, m.ind_beca, m.ind_mbeca, m.ind_cheq, m.ind_cont, m.ind_cup, p.fec_nacalu, a.cod_conv, concat(p.ape_pat_alu,' ',p.ape_mat_alu,' ',p.nom_alu) as NombreAlu FROM apo_x_alu as axa, MATRICULAS_AUX as m, postulantes as p, apoderados as a, (SELECT cc.colegio FROM hist_cod_colegio as cc, establecimientos as e WHERE e.rdb=cc.cod_rbd) as c WHERE axa.rut_apo='" & RunApo & "' AND axa.ci_alu=m.ci_alu AND m.anno_mat='" & agno & "' AND m.fec_mat<='" & agno & "-" & Format(mes, "00") & "-15' AND (m.fec_retiro='1111-11-11' OR m.fec_retiro>'" & agno & "-" & Format(mes, "00") & "-15') AND p.ci_alu=axa.ci_alu AND axa.rut_apo=a.rut_apo and axa.agno = " & agno & " ) as alu WHERE fd.colegio=alu.cole AND fd.curso=alu.curso AND fd.agno=alu.anno_mat " & _
    " ORDER BY cole, curso DESC, fec_nacalu, ci_alu;"
    
    
    Set RC = New ADODB.Recordset
    RC.Open QR, CNX
        If RC.RecordCount > 0 Then
            RC.MoveFirst
            For i = 1 To RC.RecordCount
                ReDim Preserve ValAlumnos(1 To 11, 1 To i)
                'Run Alumno
                ValAlumnos(1, i) = RC!ci_alu
                'Arancel Base
                ValAlumnos(2, i) = RC!arancel_base
                'Descuento Beca
                If RC!Ind_Beca = 1 Then
                    ValAlumnos(3, i) = RC!arancel_base
                    swBeca = True
                ElseIf RC!Ind_MBeca = 1 Then
                    ValAlumnos(3, i) = (RC!arancel_base / 2)
                    swBeca = True
                Else
                    ValAlumnos(3, i) = 0
                End If
                'Descuento Hermano
                If i > 1 And Not (swBeca) Then
                    ValAlumnos(4, i) = Int((RC!arancel_base * (RC!hermanos / 100)) + 0.5)
                    'Validacion de Año
                    If agno = 2005 Then
                        ValAlumnos(4, i) = ValAlumnos(4, i) - (ValAlumnos(4, i) Mod 100)
                    Else
                        ValAlumnos(4, i) = ValAlumnos(4, i) - (ValAlumnos(4, i) Mod 50)
                    End If
                Else
                    ValAlumnos(4, i) = 0
                End If
                'Descuento Ajuste Especial
                ValAlumnos(5, i) = 0
                'Descuento Convenio
                If Not (UCase(RC!cod_conv) = "N") And Not (swBeca) Then
                    ValAlumnos(6, i) = Int(((RC!arancel_base - ValAlumnos(4, i)) * (RC!Convenio1 / 100)) + 0.5)
                    'Validacion de año.
                    If agno = 2005 Then
                        ValAlumnos(6, i) = ValAlumnos(6, i) - (ValAlumnos(6, i) Mod 100)
                    Else
                        ValAlumnos(6, i) = ValAlumnos(6, i) - (ValAlumnos(6, i) Mod 50)
                    End If
                Else
                    ValAlumnos(6, i) = 0
                End If
                'Descuento Tipo Pago
                If Not (swBeca) Then
                    'Validacion de año.
                    If agno = 2005 Then
                        ValAlumnos(10, i) = 0
                    Else
                        If RC!Ind_Cont = 1 Then
                            'Porcentaje de Descuento contado
                            PorcentajeTipoPago = 0
                        ElseIf RC!Ind_Cheq = 1 Then
                            'Porcentaje de Descuento cheque
                            PorcentajeTipoPago = 0
                        Else
                            'Sin descuento.
                            PorcentajeTipoPago = 0
                        End If
                        ValAlumnos(10, i) = ((RC!arancel_base - ValAlumnos(4, i) - ValAlumnos(6, i)) * (PorcentajeTipoPago / 100)) \ 1
                    End If
                Else
                    ValAlumnos(10, i) = 0
                End If
                'Total a Pagar
                ValAlumnos(7, i) = ValAlumnos(2, i) - ValAlumnos(3, i) - ValAlumnos(4, i) - ValAlumnos(5, i) - ValAlumnos(6, i) - ValAlumnos(10, i)
                'Codigo del convenio
                ValAlumnos(8, i) = RC!cod_conv
                'Colegio
                ValAlumnos(9, i) = RC!cole
                ValAlumnos(10, i) = RC!nombrealu
                ValAlumnos(11, i) = IIf(IsNull(RC!ind_cup), 0, RC!ind_cup)
                RC.MoveNext
                swBeca = False
            Next i
        End If
    RC.Close
    CuotaAlumnosApoFecha = ValAlumnos
    Exit Function
Controlerror:
    errnum = Err.Number
    errdes = Err.Description
    errsou = Err.Source
    Err.Raise errnum, errsou & vbCrLf & "Form_Letras_Principal.CuotaAlumnosFecha", errdes
    'Resume
End Function

Private Sub Opt_Tipo_Fecha_Click(Index As Integer)
If Me.cmb_anho_letras(0) <> "" Then
    'llena combo de fechas
    Me.Cmb_FechaBus_Nuevos.Clear
    Me.Cmb_FechaBus_Nuevos.AddItem "<Todos>"
    Select Case Index
        Case 0 ' Fecha de Postulación
            'SqlFechaBus = " and po.fec_pos "
            Call LlenaCombo(Me.Cmb_FechaBus_Nuevos, "postulaciones", "distinct fec_pos", "where anno_pos_alu ='" & Me.cmb_anho_letras(0) & "' order by fec_pos asc", conn)
        Case 1 ' Fecha de Evaluación
            'SqlFechaBus = " and date_format(po.vii_hor_eval,'%Y-%m-%d') "
            Call LlenaCombo(Me.Cmb_FechaBus_Nuevos, "postulaciones", "distinct date_format(vii_hor_eval,'%Y-%m-%d') as fecha_eval", "where anno_pos_alu ='" & Me.cmb_anho_letras(0) & "' order by fecha_eval asc", conn)
    End Select
Else
    Me.Opt_Tipo_Fecha(Index).Value = False
    MsgBox ("Seleccione año de Postulación")
End If
End Sub

Sub LlenagrillaALu_Letras()
Dim QR As String
    
    QR = "SELECT DISTINCT fdm.run_alu, CONCAT(p.ape_pat_alu,' ',p.ape_mat_alu,' ',p.nom_alu) as nombre FROM fnza_mensualidad fm, fnza_detalle_mensualidad fdm, postulantes p WHERE fm.folio_mens=fdm.folio_mens AND fm.run_apo='" & text2.Text & "' AND p.ci_alu=fdm.run_alu AND fdm.colegio='" & ImageCombo2.SelectedItem.Key & "' order by fdm.run_alu"
    
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    For i = 1 To RC.RecordCount
        Grilla.AddItem RC("run_alu") & Chr(9) & RC("nombre"), i
        RC.MoveNext
    Next i
    RC.Close
    Frame2.Enabled = True
    Grilla.SetFocus
End Sub
Sub MatriculaAux(RunapoInd As String, RutAceptante As String, AgnoLetraInd As String, CodColegio As String, ListaAlumnos As ListBox)
Dim SqlNewAcep As String, SqlNewAcep2 As String, SqlNewMat As String, SqlNewMat2 As String, SqlNewAmbos As String
Dim SqlAntMat As String
Dim SqlAntMat2 As String
Dim RegMatAux As Integer

                '#************ALUMNOS NUEVOS***************
                'Solo Aceptados
                SqlNewAcep = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3, matri) " & _
                "(Select '" & RutAceptante & "' as rut_aceptante, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & AgnoLetraInd & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & AgnoLetraInd & "' as anhomat, '0' as indcheq, " & _
                "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3 , 'NO' " & _
                "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.agno = " & AgnoLetraInd & " and ap.rut_apo=a.rut_apo and a.rut_apo ='" & RunapoInd & "' and a.comuna_apo=cg.cod_geo and " & _
                       "p.cod_ens=c.cod_ens and po.anno_pos_alu='" & AgnoLetraInd & "' and ucase(po.viii_sit_fin_alu)='A' and " & _
                       "p.ci_alu not in (select ci_alu from matriculas where anno_mat='" & AgnoLetraInd & "' and ucase(activo_alu)='SI') " & _
                "order by a.rut_apo, p.ci_alu)"
                
                
                
'               Solo Nuevos Matriculados con tipo de pago Cuponera que estén en 2006 y no en 2005
                
                SqlNewMat = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3, matri) " & _
                "(Select '" & RutAceptante & "' as rut_aceptante, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & AgnoLetraInd & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                "'1' as reserva, '0' as can, '' as obscan, p.cod_ens, p.num_gra, '' as dest_ret, '' as obsret, po.cod_jor, " & _
                "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & AgnoLetraInd & "' as anhomat, '0' as indcheq, " & _
                "'0' as indpac, '0' as indbeca, '0' as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3, 'SI' " & _
                "From   postulantes p, postulaciones po, apoderados a, apo_x_alu ap, codigos_ensenanza c, codigos__geograficos cg " & _
                "Where  p.ci_alu=po.ci_alu and po.ci_alu=ap.ci_alu and ap.agno = " & AgnoLetraInd & " and ap.rut_apo=a.rut_apo and a.rut_apo='" & RunapoInd & "' and a.comuna_apo=cg.cod_geo and " & _
                       "p.cod_ens=c.cod_ens and po.anno_pos_alu='" & AgnoLetraInd & "' and ucase(po.viii_sit_fin_alu)='A' and " & _
                       "p.ci_alu in (select ci_alu from matriculas m, codigos_ensenanza c where m.cod_ens=c.cod_ens and m.anno_mat='" & AgnoLetraInd & "' and ucase(m.activo_alu)='SI' and m.ind_cup='1') and " & _
                       "p.ci_alu not in (select ci_alu from matriculas m, codigos_ensenanza c where m.cod_ens=c.cod_ens and m.anno_mat='" & (val(AgnoLetraInd) - 1) & "' and ucase(m.activo_alu)='SI') " & _
                "order by a.rut_apo, p.ci_alu)"
                
          
                'Solo Antiguos Matriculados con tipo de pago Cuponera que esten en 2005 y 2006
                SqlAntMat = "insert into matriculas_aux (rut_aceptante, rut_apo, noms_apo, dir_apo, comuna_apo, ci_alu, activo_alu, num_mat, fec_mat, fec_retiro, reserva, cancelado, obs_cancelado, cod_ens, num_gra, destino_retiro, obs_retiro, " & _
                "cod_jor, obs_res, cod_sit, cod_obs_fin, ind_cup, anno_mat, ind_cheq, ind_pac, ind_beca, ind_mbeca, tpago_act, cod_crit, ind_cont, cuota1, l1, l2, l3, matri) " & _
                "(Select '" & RutAceptante & "' as rut_aceptante, a.rut_apo, concat(a.noms_apo,' ', a.ape1_apo,' ', a.ape2_apo) as nombreapo, a.dir_apo, a.comuna_apo, p.ci_alu, 'SI' as act, '00000' as mat, '" & AgnoLetraInd & "-02-28' as fecmat, '1111-11-11' as fecret, " & _
                "'1' as reserva, '0' as can, '' as obscan, m.cod_ens, m.num_gra, '' as dest_ret, '' as obsret, m.cod_jor, " & _
                "'' as obres, '0' as codsit, '' as cod_obs_fin, '1' as ind_cup, '" & AgnoLetraInd & "' as anhomat, '0' as indcheq, " & _
                "'0' as indpac, m.ind_beca as indbeca, m.ind_mbeca as indmebeca , '' as tpagoact, '' as codcrit, '0' as indcont, " & _
                "'0' as cuota1, '0' as l1, '0' as l2, '0' as l3, 'SI' " & _
                "from postulantes as p, alu_x_cur as ac, apoderados as a, apo_x_alu as aa, " & _
                "matriculas As m, codigos__geograficos As cg " & _
                "where p.ci_alu = ac.Ci_alu And ac.activo_alu = 'SI' and fec_cam = '1111/11/11' and " & _
                "aa.ci_alu = p.ci_alu and aa.rut_apo = a.rut_apo and a.rut_apo ='" & RunapoInd & "' and m.activo_alu = ac.activo_alu and " & _
                "m.ci_alu = p.ci_alu and cg.cod_geo = a.comuna_apo and m.anno_mat = " & AgnoLetraInd & " and aa.agno = " & AgnoLetraInd & " and ac.agno = " & AgnoLetraInd - 1 & ")"
             
        
    'Si creó tabla auxiliar de matrículas
    If TablaMatAux Then
        If ListaAlumnos.Selected(0) Then
            'conn.Execute SqlNewAcep
        End If
        If ListaAlumnos.Selected(1) Then
            conn.Execute SqlNewMat
        End If
        If ListaAlumnos.Selected(2) Then
             conn.Execute SqlAntMat
        End If
        'Mostrar alumnos de matricula auxiliar en grilla
        'Mostrar mensaje de coincidencias
        
        'If RegMatAux > 0 Then
        '    Me.Frame_Proceso.Enabled = True
        'Else
            
            'MsgBox ("NO SE ENCONTRARON ALUMNOS")
            'Me.Frame_Proceso.Enabled = False
        'End If
        'Me.Lbl_Reg_Encontrados.Caption = RegMatAux
        'Me.Lbl_Reg_Encontrados.Refresh
    End If

'Else
'    MsgBox ("Falta seleccionar campos")
'End If


End Sub


Private Sub txt_indFolio_inicial_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9") Then
    Exit Sub
ElseIf KeyAscii = 8 Then Exit Sub
ElseIf KeyAscii = 32 Then Exit Sub
End If
KeyAscii = 0
End Sub

Private Sub Txt_IndNomApo_Letra_Change()
Dim rs As ADODB.Recordset

    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Txt_IndNomApo_Letra.Text = "" Then Exit Sub
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open "SELECT DISTINCT a.ape1_apo, a.ape2_apo, a.noms_apo FROM apoderados a, apo_x_alu aa where left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(Txt_IndNomApo_Letra.Text) & ")='" & Txt_IndNomApo_Letra.Text & "' and a.rut_apo=aa.rut_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    Me.Lst_IndNomApo_Letra.Clear
    While Not (rs.EOF)
        Me.Lst_IndNomApo_Letra.AddItem rs("ape1_apo") & " " & rs("ape2_apo") & " " & rs("noms_apo")
        rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    
    Me.Lst_IndNomApo_Letra.Visible = True
End Sub

Private Sub Txt_IndRutApo_Letra_Change()
  Dim rs As ADODB.Recordset
    
    ' Si el cambio l0o hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Txt_IndRutApo_Letra.Text = "" Then Exit Sub
    
    Set rs = New ADODB.Recordset
    Dim Str_Query As String
    rs.CursorLocation = adUseClient
    Str_Query = "SELECT DISTINCT aa.rut_apo FROM apoderados a, apo_x_alu aa WHERE left(a.rut_apo," & Len(Txt_IndRutApo_Letra.Text) & ")='" & Txt_IndRutApo_Letra.Text & "' AND a.rut_apo=aa.rut_apo "

    rs.Open Str_Query, conn
    Me.Lst_IndRutApo_Letra.Clear
    While Not (rs.EOF)
        Me.Lst_IndRutApo_Letra.AddItem rs!rut_apo
        rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    Me.Lst_IndRutApo_Letra.Visible = True
End Sub
 
Sub LlenaComboAgno()
Me.Cmb_IndAnho_Letras.Clear
Me.Cmb_IndAnho_Letras.AddItem Year(Date)
Me.Cmb_IndAnho_Letras.AddItem Year(Date) + 1
End Sub
'Sub LlenaTipoAlu()
'Me.cmb_indtipoalu_letras.Clear
'Me.cmb_indtipoalu_letras.AddItem "Nuevos  .- Aceptados"
'Me.cmb_indtipoalu_letras.AddItem "Nuevos  .- Matriculados"
'Me.cmb_indtipoalu_letras.AddItem "Antiguos.- Matriculados"
'Me.cmb_indtipoalu_letras.AddItem "Todos"
'Me.cmb_indtipoalu_letras.AddItem "Antiguos"
'Me.cmb_indtipoalu_letras.AddItem "Ambos"
'End Sub
Sub LlenaColegios()
'Debo averiguar si el apoderado tiene alumnos postulantes en
'Pk
'no Pk
'Debo averiguar si el apoderado tiene alumnos nuevos matriculados en
'Pk
'no Pk
'Debo averiguar si el apoderado tiene alumnos antiguos matriculados en
'Pk
'no Pk
End Sub
Sub LlenaComunas()
Me.Cmb_Comuna_Acep.Clear
Me.cmb_ciudad_acep.Clear
Me.cmb_codgeo_acep.Clear
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select distinct comuna, provincia, cod_geo  from codigos__geograficos order by comuna asc", conn
If rs.RecordCount > 0 Then
    While Not rs.EOF
        Me.Cmb_Comuna_Acep.AddItem rs!Comuna
        Me.cmb_ciudad_acep.AddItem rs!provincia
        Me.cmb_codgeo_acep.AddItem rs!cod_geo
        rs.MoveNext
    Wend
End If
rs.Close
Set rs = Nothing
End Sub
Sub Datostitular(Es As Boolean)
If Es Then
        Me.txt_rut_acep = Me.Txt_IndRutApo_Letra
        Set rs = New ADODB.Recordset
        rs.CursorLocation = adUseClient
        rs.Open "select noms_apo, ape1_apo, ape2_apo from apoderados where rut_apo ='" & Me.Txt_IndRutApo_Letra & "'", conn
        If rs.RecordCount > 0 Then
            Me.txt_nom_acep = rs!Noms_Apo
            Me.txt_ape_pat_acep = rs!ape1_apo
            Me.txt_ape_mat_acep = rs!ape2_apo
        End If
        rs.Close
        Set rs = Nothing
        Me.txt_dir_acep = Me.txt_dirapo_Letra
        Me.Cmb_Comuna_Acep = Me.txt_comunaapo_letra
Else
        Me.txt_rut_acep = ""
        Me.txt_nom_acep = ""
        Me.txt_dir_acep = ""
        Me.txt_ape_pat_acep = ""
        Me.txt_ape_mat_acep = ""
        Me.Cmb_Comuna_Acep.ListIndex = -1: Me.cmb_ciudad_acep.ListIndex = -1
End If
End Sub

Private Sub txt_rut_acep_LostFocus()
    Set rs = New ADODB.Recordset
    rs.Open "select * from fnza_rut_letra f, codigos__geograficos c where f.comuna_apo_letra= c.cod_geo and f.rut_letra ='" & Trim(Me.txt_rut_acep) & "'", conn
    If rs.RecordCount > 0 Then
        Me.txt_nom_acep = rs!nombre_apo_letra
        Me.txt_ape_pat_acep = rs!ape1_apo_letra
        Me.txt_ape_mat_acep = rs!ape2_apo_letra
        Me.txt_dir_acep = rs!dir_apo_letra
        Me.Cmb_Comuna_Acep = rs!Comuna
        Me.Btn_IndProcesar.SetFocus
    Else
        Me.txt_nom_acep.SetFocus
    End If
    rs.Close
    Set rs = Nothing
End Sub
Sub Lista_LetraRep(ByRef FilaLetra As Long, Folio As Long, RutAcept As String, NomAcept As String, Vencim As String, Mes_Ini As Integer, Mes_Fin As Integer, agno As String, valor As Long, Domicilio As String, Comuna As String, Ciudad As String, rutalumno As String, NomAlumno As String, Rutapod As String, NomApod As String, Clave As String, X As Integer, De As Integer, Folioint As String, fec_emis As String, CodColegio As String)
    Form_Letras_Datos.Grd_Datos_Letras_Rep.AddItem ""
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 0) = FilaLetra
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 1) = Folio
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 2) = RutAcept
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 3) = NomAcept
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 4) = Vencim
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 5) = MesATexto(Mes_Ini)
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 6) = MesATexto(Mes_Fin)
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 7) = agno
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 8) = valor
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 9) = Domicilio
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 10) = Comuna
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 11) = Ciudad
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 12) = rutalumno
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 13) = NomAlumno
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 14) = Rutapod
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 15) = NomApod
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 16) = Clave
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 17) = X
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 18) = De
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 19) = Folioint
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 20) = Mes_Ini
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 21) = Mes_Fin
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 22) = fec_emis
    Form_Letras_Datos.Grd_Datos_Letras_Rep.TextMatrix(FilaLetra, 23) = CodColegio
    Form_Letras_Datos.Refresh
End Sub
Public Sub LetraxRut(RutProc As String)
Me.Txt_IndRutApo_Letra = RutProc
Me.Lst_IndRutApo_Letra.ListIndex = 0
Call Lst_IndRutApo_Letra_DblClick
End Sub

Sub Inigrillaalu()
Me.Grd_IndAlu_Letras.Cols = 6
Me.Grd_IndAlu_Letras.Rows = 2
Me.Grd_IndAlu_Letras.FixedCols = 0
Me.Grd_IndAlu_Letras.Clear
Me.Grd_IndAlu_Letras.MergeCells = flexMergeRestrictColumns
Me.Grd_IndAlu_Letras.MergeCol(0) = False
Me.Grd_IndAlu_Letras.MergeCol(1) = False
Me.Grd_IndAlu_Letras.MergeCol(2) = False
Me.Grd_IndAlu_Letras.MergeCol(3) = False
Me.Grd_IndAlu_Letras.MergeCol(4) = False
Me.Grd_IndAlu_Letras.MergeCol(5) = False
                                          '0         1      2       3         4         5
Me.Grd_IndAlu_Letras.FormatString = " Rut Alumno| CodEns |Nivel |Rut Apod.| Año Mat. |MatReal"
Me.Grd_IndAlu_Letras.ColWidth(0) = 2000
Me.Grd_IndAlu_Letras.ColWidth(1) = 1000
Me.Grd_IndAlu_Letras.ColWidth(2) = 1000 ' estara oculta ya que no se tomará en cuenta aun
Me.Grd_IndAlu_Letras.ColWidth(3) = 2000
Me.Grd_IndAlu_Letras.ColWidth(4) = 1000
Me.Grd_IndAlu_Letras.ColWidth(5) = 1000 ' Esta columna si está realmente matriculado en sistema
End Sub
Sub ProcesaAntiguos(Agnoletraproc As String, MayorProc As Boolean, ByRef FolioLetra As Long, Fecha_emision As String)
    Dim Rutapod As String
    Dim Rut_acep_letra As String
    Dim RangoIni As Long, RangoFin As Long
    
    Form_Progress.Label1.Caption = "Generando Letras ..."
    Form_Progress.Show
    Form_Progress.ProgBar1.MaxValue = Me.grd_alumnos.Rows - 1
    RangoIni = val(FolioLetra): RangoFin = val(RangoIni + (val(Me.Lbl_Reg_Encontrados)) * 3)
    'Si hay folios ocupados en el rango proyectado
    If Not ExistReg("fnza_letra_cab", "folio_fisico >=" & RangoIni + 1 & " and folio_fisico <=" & RangoFin, conn) Then
         
        'RECORRO LA GRILLA CON UN FOR
        FilaLetra = 0: FilaLetraRep = 0
        For t = 1 To Me.grd_alumnos.Rows - 1
            If Me.grd_alumnos.TextMatrix(t, 6) = 1 Then
                Call GeneraLetras(Fecha_emision, FolioLetra, Me.grd_alumnos.TextMatrix(t, 3), Me.grd_alumnos.TextMatrix(t, 3), Me.grd_alumnos.TextMatrix(t, 0), Me.grd_alumnos.TextMatrix(t, 4), Me.grd_alumnos.TextMatrix(t, 5), Me.grd_alumnos.TextMatrix(t, 9), Agnoletraproc, Me.grd_alumnos.TextMatrix(t, 1), Me.grd_alumnos.TextMatrix(t, 2))
            End If
            
            Form_Progress.ProgBar1.ShowProgress t
            DoEvents
        Next t
        
    Else
        MsgBox ("Folio No permitido ya que se encuentra en sistema")
    End If
    Unload Form_Progress
End Sub


Sub GeneraLetras(Fecha_emision As String, ByRef FolioLetra As Long, Rut_acep_letra As String, rut_apo As String, Noms_Apo As String, dir_apo As String, comuna_apo As String, provincia_apo As String, Agnoletraproc As String, Optional Rut_Alumno_Titular As String = "", Optional Nom_alumno_titular As String = "")
    Dim Rutapod As String
    Dim aalumnos As Variant
    Dim TotalMes As Long
    Dim Mayor As Boolean
    Dim Letra1 As Long, letra2 As Long, Letra3 As Long
    Dim FolioInternoLetra As String
    Dim ClaveLetra As String
    Dim Encontro As Boolean
    Dim Abarra As Integer
    Dim RangoIni As Long, RangoFin As Long
    Dim Rslet As New ADODB.Recordset
    Dim RsVerifLetras As ADODB.Recordset
    Dim RsVal As New ADODB.Recordset
    Dim sql As String
    Dim resto, cantletras As Double
    
    
    Dim Fec_Emi_ant As String
    Fec_Emi_ant = Format(Fecha_emision, "yyyy/mm/dd")
    
    Set Rslet = New ADODB.Recordset
    Rslet.CursorLocation = adUseClient
    
    ' Esta consulta arma el valor de las letras solo para los alumnos
    ' que tengan tipo de pago cuponera.
    sqllet = "select aa.rut_apo, sum(fd.monto_tot_cuota) as monto_mens " & _
    "from apo_x_alu aa, matriculas m , fnza_detalle_mensualidad fd " & _
    "where aa.rut_apo ='" & rut_apo & "' and aa.ci_alu=m.ci_alu and m.ci_alu=fd.run_alu and m.anno_mat=fd.agno and fd.agno=" & Agnoletraproc & " and m.ind_cup=1 and fd.agno = aa.agno " & _
    "group by aa.rut_apo, fd.fech_venc order by fech_venc ASC limit 1"
    
    sqllet = "select sum(fdm.monto_tot_cuota)  as  monto_mens , fdm.mes, fdm.agno from fnza_mensualidad fm, fnza_detalle_mensualidad fdm, matriculas m  where fm.run_apo= '" & rut_apo & "' and fm.agno = " & Agnoletraproc & " and fdm.agno = " & Agnoletraproc & " and fm.mes > 2 and fm.folio_mens = fdm.folio_mens and fdm.run_alu = m.ci_alu and m.ind_cup=1 and m.anno_mat = " & Agnoletraproc & " group by fdm.mes, fdm.agno limit 1;"
    'Esta Consulta no sirve ya que no discrimina tipos de pagos
    'sqllet = "select sum(monto_mens) as monto_mens from fnza_mensualidad where run_apo='" & Rut_apo & "' and agno =" & Agnoletraproc & " group by fech_venc order by fech_venc asc limit 1"
    
    Rslet.Open sqllet, conn
    If Rslet.RecordCount > 0 Then
        TotalMes = Rslet!Monto_Mens
        If TotalMes = 0 Then GoTo TerminaSub
        '***************************************************************
        'nuevo codigo para solucionar el de las letras que no son fijas
        sql = "SELECT fdm.mes, sum(fdm.monto_tot_cuota) as total FROM fnza_mensualidad fm, fnza_detalle_mensualidad fdm, matriculas m WHERE fm.run_apo= '" & rut_apo & "' and fm.agno = " & Agnoletraproc & " and fdm.agno = " & Agnoletraproc & " and fdm.concepto <> 'ct00' and fm.folio_mens = fdm.folio_mens and fdm.run_alu = m.ci_alu and m.ind_cup=1 and m.anno_mat = " & Agnoletraproc & " GROUP BY fdm.mes ;"
        RsVal.Open sql, conn
        resto = RsVal.RecordCount Mod 3
        cantletras = RsVal.RecordCount \ 3
        ValorContrato = RsVal!total
        Letra1 = 0
        letra2 = 0
        Letra3 = 0
        If cantletras = 3 Then
           Letra1 = 3 + resto
        End If
        If cantletras > 2 Then
           letra2 = 3
        End If
        If cantletras = 2 Then
           letra2 = 3 + resto
        End If
        If cantletras > 1 Then
           Letra3 = 3
        End If
        If cantletras = 1 Then
           Letra3 = 3 + resto
        End If
        If cantletras = 0 Then
           Letra3 = resto
        End If
        Letra1 = Letra1 * TotalMes
        letra2 = letra2 * TotalMes
        Letra3 = Letra3 * TotalMes
        
        
        
        '***************************************************************
'        ValorContrato = TotalMes * 11
'        Letra1 = TotalMes * 4 'Marzo Abril Mayo Junio
'        Letra2 = TotalMes * 3 'Julio Agosto Septiembre
'        Letra3 = TotalMes * 3 'Octubre Noviembre Diciembre
            
        'VERIFICAR SI LETRA1 NO EXISTE EN SISTEMA
        
        Set RsVerifLetras = New ADODB.Recordset
        If Letra1 > 0 Then
            RsVerifLetras.CursorLocation = adUseClient
            RsVerifLetras.Open "(select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-06-10' and f.estado_letra <>'A'  and f.agno = aa.agno) " & _
            "Union " & _
            "( select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-06-10' and f.estado_letra <>'A' and f.agno = aa.agno)", conn
    
                            
            If RsVerifLetras.RecordCount > 0 Then
                FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, RsVerifLetras!run_alu, RsVerifLetras!nombrealu, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 1, 3, RsVerifLetras!folio_interno, Fec_Emi_ant, CodColegioLetra)
            Else
                FilaLetra = FilaLetra + 1
                FolioLetra = FolioLetra + 1
                    Call Lista_Letra(FilaLetra, FolioLetra, Rut_acep_letra, Noms_Apo, Agnoletraproc & "-06-10", 3, 6, Agnoletraproc, Letra1, dir_apo, comuna_apo, provincia_apo, Rut_Alumno_Titular, Nom_alumno_titular, rut_apo, Noms_Apo, ClaveLetra, 1, 3, FolioInternoLetra, Fec_Emi_ant, CodColegioLetra)
            End If
            RsVerifLetras.Close
        End If
        'VERIFICAR SI LETRA2 NO EXISTE EN SISTEMA
        If letra2 > 0 Then
            RsVerifLetras.Open "(select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':', f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-09-10' and f.estado_letra <>'A' and aa.agno = f.agno) " & _
            "Union " & _
            "( select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-09-10' and f.estado_letra <>'A' and aa.agno = f.agno)", conn
    
            If RsVerifLetras.RecordCount > 0 Then
                FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, RsVerifLetras!run_alu, RsVerifLetras!nombrealu, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 2, 3, RsVerifLetras!folio_interno, Fec_Emi_ant, CodColegioLetra)
            Else
                FilaLetra = FilaLetra + 1
                FolioLetra = FolioLetra + 1
                Call Lista_Letra(FilaLetra, FolioLetra, Rut_acep_letra, Noms_Apo, Agnoletraproc & "-09-10", 7, 9, Agnoletraproc, letra2, dir_apo, comuna_apo, provincia_apo, Rut_Alumno_Titular, Nom_alumno_titular, rut_apo, Noms_Apo, ClaveLetra, 2, 3, FolioInternoLetra, Fec_Emi_ant, CodColegioLetra)
            End If
            RsVerifLetras.Close
        End If
        'VERIFICAR SI LETRA3 NO EXISTE EN SISTEMA
        If Letra3 > 0 Then
            RsVerifLetras.Open "(select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(a.noms_apo,' ',a.ape1_apo,' ',a.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':', f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo = c.cod_geo And p.Ci_alu = aa.Ci_alu And aa.Ci_alu = f.run_alu And aa.rut_apo = f.rut_aceptante And f.rut_aceptante = a.rut_apo and f.run_apo=f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-12-10' and f.estado_letra <>'A' and aa.agno = f.agno ) " & _
            "Union " & _
            "( select f.folio_interno, f.folio_fisico, f.rut_aceptante, concat(a.nombre_apo_letra,' ',a.ape1_apo_letra,' ',a.ape2_apo_letra) as nombreacep, f.fecha_letra, f.periodo_ini, f.periodo_fin, f.agno, f.monto_letra, a.dir_apo_letra as dirapo, c.comuna, c.provincia, f.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombrealu, f.run_apo, concat(ap.noms_apo,' ',ap.ape1_apo,' ',ap.ape2_apo) as nombreapo, concat(f.folio_fisico,'-',f.folio_interno,':',f.agno,'-',f.colegio) as clave " & _
            "From fnza_letra_cab f, apoderados ap, fnza_rut_letra a, codigos__geograficos c, apo_x_alu aa, postulantes p Where a.comuna_apo_letra=c.cod_geo and p.ci_alu=aa.ci_alu and aa.ci_alu=f.run_alu and aa.rut_apo = ap.rut_apo and ap.rut_apo=f.run_apo and f.rut_aceptante=a.rut_letra and f.run_apo<>f.rut_aceptante and f.colegio ='" & CodColegioLetra & "' and f.agno =" & Agnoletraproc & " and f.rut_aceptante ='" & rut_apo & "' and f.fecha_letra ='" & Agnoletraproc & "-12-10' and f.estado_letra <>'A' and aa.agno = f.agno)", conn
                                  
            If RsVerifLetras.RecordCount > 0 Then
                FilaLetraRep = FilaLetraRep + 1: Call Lista_LetraRep(FilaLetraRep, RsVerifLetras!Folio_fisico, RsVerifLetras!rut_aceptante, RsVerifLetras!nombreacep, RsVerifLetras!fecha_letra, RsVerifLetras!periodo_ini, RsVerifLetras!periodo_fin, RsVerifLetras!agno, RsVerifLetras!monto_letra, RsVerifLetras!dirapo, RsVerifLetras!Comuna, RsVerifLetras!provincia, RsVerifLetras!run_alu, RsVerifLetras!nombrealu, RsVerifLetras!run_apo, RsVerifLetras!nombreapo, RsVerifLetras!Clave, 3, 3, RsVerifLetras!folio_interno, Fec_Emi_ant, CodColegioLetra)
            Else
                FilaLetra = FilaLetra + 1
                FolioLetra = FolioLetra + 1
                Call Lista_Letra(FilaLetra, FolioLetra, Rut_acep_letra, Noms_Apo, Agnoletraproc & "-12-10", 10, 12, Agnoletraproc, Letra3, dir_apo, comuna_apo, provincia_apo, Rut_Alumno_Titular, Nom_alumno_titular, rut_apo, Noms_Apo, ClaveLetra, 3, 3, FolioInternoLetra, Fec_Emi_ant, CodColegioLetra)
            End If
            RsVerifLetras.Close
        End If
        '****************Proc. Temporal******************
    Else
        'MsgBox ("Apoderado")
    End If
TerminaSub:
    Rslet.Close
    'RsVerifLetras.Close
End Sub




