VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form Form_cuotas_vencidas 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cuotas Vencidas"
   ClientHeight    =   7860
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   12795
   Icon            =   "Form_cuotas_vencidas.frx":0000
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7860
   ScaleWidth      =   12795
   Begin VB.Frame Frame4 
      Caption         =   "Seleccione Mes"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   2040
      TabIndex        =   20
      Top             =   120
      Visible         =   0   'False
      Width           =   10575
      Begin VB.ComboBox cb_agno 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   240
         TabIndex        =   25
         Text            =   "Combo1"
         Top             =   480
         Width           =   1095
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Ver"
         Height          =   375
         Left            =   9600
         TabIndex        =   22
         Top             =   480
         Width           =   735
      End
      Begin VB.ComboBox IC_MES2 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1440
         TabIndex        =   21
         Text            =   "Combo1"
         Top             =   480
         Width           =   1575
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         Caption         =   "Año"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   120
         TabIndex        =   24
         Top             =   240
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "Mes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1560
         TabIndex        =   23
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Seleccionar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   120
      TabIndex        =   17
      Top             =   120
      Width           =   1815
      Begin VB.OptionButton Option2 
         Caption         =   "Todos"
         BeginProperty Font 
            Name            =   "Arial Narrow"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   19
         Top             =   720
         Width           =   1095
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Por Curso"
         BeginProperty Font 
            Name            =   "Arial Narrow"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   240
         TabIndex        =   18
         Top             =   360
         Value           =   -1  'True
         Width           =   1455
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Seleccione Curso"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   2040
      TabIndex        =   4
      Top             =   120
      Width           =   10575
      Begin VB.ComboBox IC_mes 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   7800
         TabIndex        =   15
         Text            =   "Combo1"
         Top             =   480
         Width           =   1575
      End
      Begin VB.CheckBox Check_Letra 
         Caption         =   "Letra"
         ForeColor       =   &H00000000&
         Height          =   195
         Left            =   6600
         TabIndex        =   6
         Top             =   240
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1095
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Ver"
         Height          =   375
         Left            =   9600
         TabIndex        =   5
         Top             =   480
         Width           =   735
      End
      Begin MSComctlLib.ImageCombo IC_Ensenanza 
         Height          =   345
         Left            =   1440
         TabIndex        =   7
         Top             =   480
         Width           =   3855
         _ExtentX        =   6800
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
         Text            =   "IC_Ensenanza"
      End
      Begin MSComctlLib.ImageCombo IC_Nivel 
         Height          =   345
         Left            =   5400
         TabIndex        =   8
         Top             =   480
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
         Text            =   "IC_Nivel"
      End
      Begin MSComctlLib.ImageCombo IC_Letra 
         Height          =   345
         Left            =   6600
         TabIndex        =   9
         Top             =   480
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
         Text            =   "IC_Letra"
      End
      Begin MSComctlLib.ImageCombo IC_Agno 
         Height          =   345
         Left            =   240
         TabIndex        =   10
         Top             =   480
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
         Text            =   "IC_Agno"
      End
      Begin VB.Label Label4 
         Caption         =   "Mes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7800
         TabIndex        =   16
         Top             =   240
         Width           =   1095
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "Nivel"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   5280
         TabIndex        =   13
         Top             =   240
         Width           =   615
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Enseñanza"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   1440
         TabIndex        =   12
         Top             =   240
         Width           =   975
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         Caption         =   "Año"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   120
         TabIndex        =   11
         Top             =   240
         Width           =   495
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Listado 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          =   4935
      Left            =   120
      TabIndex        =   2
      Top             =   1440
      Width           =   12495
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   4575
         Left            =   120
         TabIndex        =   3
         Top             =   240
         Width           =   12255
         _ExtentX        =   21616
         _ExtentY        =   8070
         _Version        =   393216
      End
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Exportar Excel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   1320
      Picture         =   "Form_cuotas_vencidas.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   6840
      Width           =   1575
   End
   Begin VB.CommandButton cmd_salir 
      Caption         =   "Salir"
      Height          =   855
      Left            =   9720
      Picture         =   "Form_cuotas_vencidas.frx":2AE98
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   6840
      Width           =   1575
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   14
      Top             =   6480
      Width           =   12495
      _ExtentX        =   22040
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
End
Attribute VB_Name = "Form_cuotas_vencidas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.Clear
    If REC.RecordCount > 0 Then
        grid.Cols = REC.Fields.count + 1
        grid.Rows = REC.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nº"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For i = 1 To REC.Fields.count
            grid.TextMatrix(0, i) = UCase(REC.Fields(i - 1).Name)
            grid.ColWidth(i) = TextWidth(grid.TextMatrix(0, i)) + 100
        Next i
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            'progreso.Value = i
            grid.TextMatrix(i, 0) = i
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(i, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(i, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To REC.Fields.count
                grid.TextMatrix(i, j) = IIf(IsNull(REC(j - 1)), "Null", REC(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(i, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(i, j)) + 100, grid.ColWidth(j))
            Next j
            REC.MoveNext
        Next i
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

Private Sub cmd_limpiar_Click()
    limpiar
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    Dim Mes As Integer
    Dim mes_texto As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim varsql As String
'    varsql = "SELECT curso,rut_alumno,alumno,direccion_alumno,d.comuna,telefono_alumno,correo_alumno," _
'           & "rut_apoderado , Apoderado, direccion_apoderado, cg.Comuna, telefono_apoderado, celular_apoderado, telefono_empresa, telefono_adicional_1" _
'           & ",telefono_adicional_2,correo_apoderado FROM " _
'           & " (SELECT CONCAT(c.num_gra,' ',c.let_cur,' ',CAST(IF(c.cod_ens = '111','PlayGroup',IF(c.cod_ens = '996','Pre-Kinder',IF(c.cod_ens = '010','Kinder',IF(c.cod_ens = '110','Basico',IF(c.cod_ens = '310','Media','Otro'))))) AS CHAR)) AS curso" _
'           & ",c.ci_alu AS rut_alumno,CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,dire_alu AS direccion_alumno,comuna,fon_alu AS telefono_alumno,email_alu AS correo_alumno," _
'           & "a.rut_apo AS rut_apoderado,CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) AS apoderado,dir_apo AS direccion_apoderado,comuna_apo,fon_c_apo AS telefono_apoderado,cel_apo AS celular_apoderado,empresa_fon AS telefono_empresa,telefono_adicional_1" _
'           & ",telefono_adicional_2,email AS correo_apoderado" _
'           & " FROM alu_x_cur c,postulantes p,apo_x_alu a,apoderados ap,codigos__geograficos cg" _
'           & " Where c.ci_alu = p.ci_alu And c.agno = " & Trim(IC_Agno.SelectedItem.Text) & " And c.agno = a.agno And c.ci_alu = a.ci_alu" _
'           & " AND a.rut_apo = ap.rut_apo AND p.cod_geo = cg.cod_geo AND c.activo_alu = 'SI'" _
'           & " AND c.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND c.num_gra = " & Trim(IC_Nivel.SelectedItem.Text) & " AND c.let_cur = '" & IC_Letra.Text & "') AS d" _
'           & " Left Join" _
'           & " codigos__geograficos cg" _
'           & " ON d.comuna_apo = cg.cod_geo order by alumno"
    
    'if IC_mes.Text
    
    limpiar
        
    If Option1.Value = True Then
        If IC_mes.Text = "" Then
            MsgBox "Primero debe seleccionar un mes", vbInformation
            Exit Sub
        End If
        mes_texto = IC_mes.Text
    Else
        If IC_MES2.Text = "" Then
            MsgBox "Primero debe seleccionar un mes", vbInformation
            Exit Sub
        End If
        mes_texto = IC_MES2.Text
    End If
        
    Select Case mes_texto
        Case "FEBRERO"
            Mes = 2
        Case "MARZO"
            Mes = 3
        Case "ABRIL"
            Mes = 4
        Case "MAYO"
            Mes = 5
        Case "JUNIO"
            Mes = 6
        Case "JULIO"
            Mes = 7
        Case "AGOSTO"
            Mes = 8
        Case "SEPTIEMBRE"
            Mes = 9
        Case "OCTUBRE"
            Mes = 10
        Case "NOVIEMBRE"
            Mes = 11
        Case "DICIEMBRE"
            Mes = 12
    End Select
                       
    If Option1.Value = True Then
    varsql = "SELECT dm.agno as 'Año',nom_est AS Establecimiento,CONCAT(CAST(c.num_gra AS CHAR),' ',c.let_cur,' ',IF(c.cod_ens = '996','PRE-KINDER'," _
           & "IF(c.cod_ens = '010','KINDER',IF(c.cod_ens = '110','BASICO',IF(c.cod_ens = '310','MEDIA','PLAY GROUP'))))) curso," _
           & "CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) AS apoderado,a.rut_apo,dir_apo AS Direccion,fon_c_apo AS Telefono,empresa_fon AS Telefono_empresa," _
           & "cel_apo AS Celular,if(telefono_adicional_1 is null,'',telefono_adicional_1) as telefono_adicional_1,if(telefono_adicional_2 is null,'',telefono_adicional_2) as telefono_adicional_2," _
           & "CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,dm.run_alu,fech_venc as Fecha_vencimiento,SUM(IF((monto_tot_cuota-monto_abono) >= 13500,(monto_tot_cuota-monto_abono),0)) AS Mes_deuda" _
           & " FROM establecimientos,fnza_detalle_mensualidad dm,alu_x_cur c,apo_x_alu axc,postulantes p,apoderados a,codigos__geograficos cg" _
           & " WHERE c.activo_alu = 'SI' AND dm.run_alu = c.ci_alu AND c.ci_alu = axc.ci_alu AND dm.agno = c.agno AND c.agno = axc.agno AND dm.agno = " & Trim(IC_Agno.SelectedItem.Text) _
           & " AND dm.mes <> 2" _
           & " AND dm.run_alu = p.ci_alu AND axc.rut_apo = a.rut_apo AND dm.agno = " & Trim(IC_Agno.SelectedItem.Text) _
           & " AND dm.mes = " & Mes & " AND a.comuna_apo = cg.cod_geo" _
           & " AND DATE_FORMAT(NOW(),'%Y-%m-%d') > fech_venc AND c.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND c.num_gra = " & Trim(IC_Nivel.SelectedItem.Text) _
           & " AND c.let_cur = '" & IC_Letra.Text & "'" _
           & " GROUP BY a.rut_apo,dm.run_alu" _
           & " HAVING SUM(IF((monto_tot_cuota-monto_abono) >= 13500,(monto_tot_cuota-monto_abono),0)) > 0" _
           & " ORDER BY apoderado"
    Else
    varsql = "SELECT dm.agno as 'Año',nom_est AS Establecimiento,CONCAT(CAST(c.num_gra AS CHAR),' ',c.let_cur,' ',IF(c.cod_ens = '996','PRE-KINDER'," _
           & "IF(c.cod_ens = '010','KINDER',IF(c.cod_ens = '110','BASICO',IF(c.cod_ens = '310','MEDIA','PLAY GROUP'))))) curso," _
           & "CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) AS apoderado,a.rut_apo,dir_apo AS Direccion,fon_c_apo AS Telefono,empresa_fon AS Telefono_empresa," _
           & "cel_apo AS Celular,if(telefono_adicional_1 is null,'',telefono_adicional_1) as telefono_adicional_1,if(telefono_adicional_2 is null,'',telefono_adicional_2) as telefono_adicional_2," _
           & "CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,dm.run_alu,fech_venc as Fecha_vencimiento,SUM(IF((monto_tot_cuota-monto_abono) >= 13500,(monto_tot_cuota-monto_abono),0)) AS Mes_deuda" _
           & " FROM establecimientos,fnza_detalle_mensualidad dm,alu_x_cur c,apo_x_alu axc,postulantes p,apoderados a,codigos__geograficos cg" _
           & " WHERE c.activo_alu = 'SI' AND dm.run_alu = c.ci_alu AND c.ci_alu = axc.ci_alu AND dm.agno = c.agno AND c.agno = axc.agno AND dm.agno = " & Trim(IC_Agno.SelectedItem.Text) _
           & " AND dm.mes <> 2" _
           & " AND dm.run_alu = p.ci_alu AND axc.rut_apo = a.rut_apo AND dm.agno = " & Trim(IC_Agno.SelectedItem.Text) _
           & " AND dm.mes = " & Mes & " AND a.comuna_apo = cg.cod_geo" _
           & " AND DATE_FORMAT(NOW(),'%Y-%m-%d') > fech_venc" _
           & " GROUP BY a.rut_apo,dm.run_alu" _
           & " HAVING SUM(IF((monto_tot_cuota-monto_abono) >= 13500,(monto_tot_cuota-monto_abono),0)) > 0" _
           & " ORDER BY curso,apoderado"
    End If
    
    objRS.Open varsql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
    Else
        MsgBox "Esta mensualidad aún no ha vencido", vbInformation
    End If
    objRS.Close
    MSFlexGrid1.Refresh
End Sub

Private Sub Command2_Click()
    
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For i = 1 To Me.MSFlexGrid1.Cols - 1
        ApExcel.Cells(1, i).Font.Size = 12
        ApExcel.Cells(1, i).Font.Bold = True
        ApExcel.Cells(1, i).Formula = Me.MSFlexGrid1.TextMatrix(0, i)
    Next i
    pgbar.Min = 1
    pgbar.Max = MSFlexGrid1.Rows
    pgbar.Value = pgbar.Min
    For i = 1 To MSFlexGrid1.Rows - 1

         For j = 1 To MSFlexGrid1.Cols - 1
            ApExcel.Cells((i + 1), j).Formula = MSFlexGrid1.TextMatrix(i, j)
        
        pgbar.Value = i
        Next j
    Next i
            
    ApExcel.Visible = True
    ApExcel.Range("a1:o1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing

End Sub

Private Sub Command3_Click()
    Command1_Click
End Sub

Private Sub Form_Load()
' Setear el combo años.
    Me.Top = 0
    Me.Left = 0
    IC_Letra.Text = ""
    IC_Letra.ComboItems.Clear
    Call Set_IC_Agno
    ' Limpiar textos
    'txt_nom_alu.Text = ""
    'txt_rut_alu.Text = ""
    'txt_nom_apo.Text = ""
    'txt_rut_apo.Text = ""
    'Mostrar opcion de curso al iniciar
    'Option1(0).Value = True
    'MuestraFrame ("curso")
    ErrorStatus = False
        
    IC_mes.AddItem "MARZO"
    IC_mes.AddItem "ABRIL"
    IC_mes.AddItem "MAYO"
    IC_mes.AddItem "JUNIO"
    IC_mes.AddItem "JULIO"
    IC_mes.AddItem "AGOSTO"
    IC_mes.AddItem "SEPTIEMBRE"
    IC_mes.AddItem "OCTUBRE"
    IC_mes.AddItem "NOVIEMBRE"
    IC_mes.AddItem "DICIEMBRE"
    IC_mes.Text = ""
    
    IC_MES2.AddItem "MARZO"
    IC_MES2.AddItem "ABRIL"
    IC_MES2.AddItem "MAYO"
    IC_MES2.AddItem "JUNIO"
    IC_MES2.AddItem "JULIO"
    IC_MES2.AddItem "AGOSTO"
    IC_MES2.AddItem "SEPTIEMBRE"
    IC_MES2.AddItem "OCTUBRE"
    IC_MES2.AddItem "NOVIEMBRE"
    IC_MES2.AddItem "DICIEMBRE"
    IC_MES2.Text = ""
    
    cb_agno.AddItem Year(Date)
    cb_agno.AddItem Year(Date) + 1
    cb_agno.Text = Year(Date)
        
End Sub

Private Sub IC_Agno_Click()
    IC_Ensenanza.Enabled = True
    Set_IC_Ensenanza
End Sub




Private Sub Set_IC_Ensenanza()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    QRY = "SELECT DISTINCT m.cod_ens, ce.des_ens FROM matriculas as m, codigos_ensenanza as ce WHERE m.cod_ens=ce.cod_ens AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY ce.ord_ens;"
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Ensenanza.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Ensenanza.ComboItems.Add i, "K" & Format(REC!Cod_Ens, "000"), REC!des_ens
            REC.MoveNext
        Next i
        Set IC_Ensenanza.SelectedItem = IC_Ensenanza.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        IC_Nivel.Enabled = True
        IC_Letra.Enabled = False
        Call Set_IC_Nivel
    Else
        ErrorStatus = True
        IC_Ensenanza.Enabled = False
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub IC_Ensenanza_Click()
    IC_Nivel.Enabled = True
    Call Set_IC_Nivel
End Sub

Private Sub Set_IC_Nivel()
    Dim REC As ADODB.Recordset
    Dim QRY As String

    QRY = "SELECT DISTINCT m.num_gra FROM matriculas as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY m.num_gra;"
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Nivel.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Nivel.ComboItems.Add i, , str(REC!Num_Gra)
            REC.MoveNext
        Next i
        Set IC_Nivel.SelectedItem = IC_Nivel.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        If Check_Letra.Value = 1 Then
            IC_Letra.Enabled = True
            Call Set_IC_Letra
        End If
    Else
        ErrorStatus = True
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub IC_mes_Click()
    MSFlexGrid1.Clear
    MSFlexGrid1.Cols = 2
    MSFlexGrid1.Rows = 2
End Sub

Private Sub IC_Nivel_Click()
  '  If Check_Letra.Value = 1 Then
        IC_Letra.Enabled = True
        Call Set_IC_Letra
   ' End If
End Sub

Private Sub Set_IC_Letra()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    'If Check_Letra.Value = 1 Then
        IC_Letra.ComboItems.Clear
        IC_Letra.Text = ""
        QRY = "SELECT DISTINCT m.let_cur FROM alu_x_cur as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.agno=" & Trim(IC_Agno.SelectedItem.Text) & " AND m.num_gra='" & Trim(IC_Nivel.SelectedItem.Text) & "' ORDER BY m.num_gra;"
        Set REC = New ADODB.Recordset
        REC.Open QRY, conn
        If REC.RecordCount > 0 Then
            REC.MoveFirst
            For i = 1 To REC.RecordCount
                IC_Letra.ComboItems.Add i, , REC!Let_Cur
                REC.MoveNext
            Next i
            Set IC_Letra.SelectedItem = IC_Letra.ComboItems.Item(1)
            ErrorStatus = False
            ' Llenar Siguiente Combo.
        Else
            ErrorStatus = True
            Check_Letra.Value = 0
            IC_Letra.Enabled = False
        End If
        REC.Close
'    Else
'        ErrorStatus = False
'        IC_Letra.Enabled = False
'    End If
End Sub

Private Sub Check_Letra_Click()
    If Check_Letra.Value = 0 Then
        IC_Letra.Enabled = False
    ElseIf Check_Letra.Value = 1 And Not (ErrorStatus) And IC_Ensenanza.Enabled And IC_Nivel.Enabled Then
        IC_Letra.Enabled = True
        Call Set_IC_Letra
    Else
        Check_Letra.Value = 0
        IC_Letra.Enabled = False
    End If
End Sub

Private Sub Set_IC_Agno()
    Dim agno As Integer
   
    agno = IIf(Year(Date) < 2005, 2005, Year(Date))
    IC_Agno.ComboItems.Clear
    For i = 1 To (agno - 2004)
        IC_Agno.ComboItems.Add i, , str(i + 2004)
    Next i
    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(i - 1)
    ErrorStatus = False
    
    ' Llenar combo enseñanza
    IC_Ensenanza.Enabled = True
    IC_Nivel.Enabled = False
    IC_Letra.Enabled = False
    Call Set_IC_Ensenanza
End Sub

Private Sub limpiar()
    'frame_profesores.Caption = ""
    MSFlexGrid1.Clear
    MSFlexGrid1.Rows = 2
End Sub



Private Sub Option1_Click()
    Frame1.Visible = True
    Frame4.Visible = False
End Sub

Private Sub Option2_Click()
    Frame4.Visible = True
    Frame1.Visible = False
End Sub
