VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form FormDecProm 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Decretos de evaluación y promoción"
   ClientHeight    =   4710
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10815
   Icon            =   "FormDecProm.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4710
   ScaleWidth      =   10815
   ShowInTaskbar   =   0   'False
   Begin VB.PictureBox PicValoresCrit 
      Height          =   1815
      Left            =   120
      ScaleHeight     =   1755
      ScaleWidth      =   2475
      TabIndex        =   7
      Top             =   840
      Visible         =   0   'False
      Width           =   2535
      Begin VB.Frame FrmValoresCrit 
         Caption         =   "Notas deficientes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   855
         Left            =   120
         TabIndex        =   8
         Top             =   120
         Width           =   2295
         Begin VB.ComboBox CmdValoresCrit 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   120
            Sorted          =   -1  'True
            Style           =   2  'Dropdown List
            TabIndex        =   23
            Top             =   360
            Width           =   2055
         End
      End
      Begin VB.CommandButton BtnCanValoresCrit 
         Caption         =   "Cerrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1320
         TabIndex        =   10
         Top             =   1200
         Width           =   975
      End
      Begin VB.CommandButton BtnAceValoresCrit 
         Caption         =   "Aceptar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   9
         Top             =   1200
         Width           =   975
      End
   End
   Begin VB.CommandButton BtnCanCri 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   9360
      TabIndex        =   22
      Top             =   4200
      Width           =   1335
   End
   Begin VB.CommandButton BtnGraCri 
      Caption         =   "Grabar"
      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
      Left            =   7800
      TabIndex        =   21
      Top             =   4200
      Width           =   1455
   End
   Begin VB.Frame Frame1 
      Caption         =   "Criterio"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2535
      Left            =   120
      TabIndex        =   17
      Top             =   120
      Width           =   7575
      Begin VB.CommandButton BtnSubGrid1 
         Caption         =   "--"
         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
         Left            =   7200
         TabIndex        =   20
         Top             =   600
         Width           =   255
      End
      Begin VB.CommandButton BtnAddGrid1 
         Caption         =   "+"
         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
         Left            =   7200
         TabIndex        =   19
         Top             =   240
         Width           =   255
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   2175
         Left            =   120
         TabIndex        =   18
         Top             =   240
         Width           =   6975
         _ExtentX        =   12303
         _ExtentY        =   3836
         _Version        =   393216
         Cols            =   6
         FixedCols       =   0
         ScrollBars      =   2
         FormatString    =   "ID    | Nº de Notas Deftes.| Nota Subsector Defte.|Prom. Final |Prom. Automática| % Asis"
         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
   End
   Begin VB.Frame Frame2 
      Caption         =   "Exepción de Subsectores"
      Enabled         =   0   'False
      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        =   0
      Top             =   2760
      Width           =   7575
      Begin VB.CheckBox chkNingunaExc 
         Alignment       =   1  'Right Justify
         Caption         =   "Ninguno"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Index           =   0
         Left            =   6120
         TabIndex        =   24
         Top             =   240
         Width           =   975
      End
      Begin VB.CommandButton Command2 
         Caption         =   "--"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7200
         TabIndex        =   3
         Top             =   600
         Width           =   255
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid2 
         Height          =   1215
         Index           =   0
         Left            =   120
         TabIndex        =   2
         Top             =   480
         Width           =   6975
         _ExtentX        =   12303
         _ExtentY        =   2143
         _Version        =   393216
         FixedCols       =   0
         FormatString    =   "Nombre del Subsector                                                                                                  | Nota"
         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.CommandButton Command1 
         Caption         =   "+"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7200
         TabIndex        =   1
         Top             =   240
         Width           =   255
      End
   End
   Begin VB.Frame FrmCodIntervienen 
      Caption         =   "Códigos que Intervienen"
      Enabled         =   0   'False
      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            =   7800
      TabIndex        =   4
      Top             =   2520
      Width           =   2895
      Begin VB.CommandButton CargaDecProm 
         Caption         =   "><"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2400
         TabIndex        =   11
         Top             =   600
         Width           =   375
      End
      Begin VB.CheckBox chk_Todos_cod 
         Caption         =   "Todos los códigos"
         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        =   6
         Top             =   1200
         Width           =   1695
      End
      Begin VB.ListBox lst_DecProm 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   780
         Index           =   0
         Left            =   120
         Style           =   1  'Checkbox
         TabIndex        =   5
         Top             =   360
         Width           =   2175
      End
   End
   Begin VB.Frame FrmNivAplica 
      Caption         =   "Niveles en que se aplica"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2295
      Left            =   7800
      TabIndex        =   12
      Top             =   120
      Width           =   2895
      Begin VB.CheckBox chk_todos_niveles 
         Caption         =   "Todos los niveles"
         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        =   16
         Top             =   1920
         Width           =   1575
      End
      Begin VB.ListBox lst_niveles 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   780
         Index           =   0
         Left            =   120
         Style           =   1  'Checkbox
         TabIndex        =   15
         Top             =   1080
         Width           =   2655
      End
      Begin VB.ComboBox cmb_cod_ens 
         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            =   120
         TabIndex        =   13
         Top             =   600
         Width           =   2655
      End
      Begin VB.Label Label3 
         Caption         =   "Tipo de 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
         Left            =   120
         TabIndex        =   14
         Top             =   360
         Width           =   1575
      End
   End
End
Attribute VB_Name = "FormDecProm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim NumItem As Integer
Dim grilla, CodModalidad As String
Dim SelcursosM() As String
Dim Entro, EntroChkNingunaExc As String

Public Sub AddItemGrd(NameGrd As Control)
    NameGrd.Col = 0
    NameGrd.AddItem ""
    NameGrd.Row = NameGrd.Rows - 1
    NameGrd.CellBackColor = &HFFFFFF
    NameGrd.SetFocus
End Sub
Sub MuestraPicValoresCrit()

Select Case grilla
Case 1
Me.PicValoresCrit.Width = 2415
Me.PicValoresCrit.Left = 7680
Me.PicValoresCrit.Top = 120
Me.FrmValoresCrit.Width = 2055
Me.CmdValoresCrit.Width = 1815
Me.BtnAceValoresCrit.Left = 120
Me.BtnAceValoresCrit.Top = 1200
Me.BtnCanValoresCrit.Left = 1200
Me.BtnCanValoresCrit.Top = 1200

Select Case MSFlexGrid1.Col
Case 1
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Nº de Notas Deficientes"
    Me.CmdValoresCrit.Clear
    For i = 0 To 9
        Me.CmdValoresCrit.AddItem "0" & i
    Next i
    Me.CmdValoresCrit.AddItem i
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
    
Case 2
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Nota Min. Subsector Def."
    Me.CmdValoresCrit.Clear
    For i = 1 To 7
        For j = 0 To 9
            Me.CmdValoresCrit.AddItem i & "," & j
            If i = 7 Then Exit For
        Next j
    Next i
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
    
Case 3
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Promedio Mínimo final"
    Me.CmdValoresCrit.Clear
    For i = 1 To 7
        For j = 0 To 9
            Me.CmdValoresCrit.AddItem i & "," & j
            If i = 7 Then Exit For
        Next j
    Next i
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
    
    
Case 4
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Promoción automática"
    Me.CmdValoresCrit.Clear
    Me.CmdValoresCrit.AddItem "SI"
    Me.CmdValoresCrit.AddItem "NO"
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
    
Case 5
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Asistencia Mínima"
    Me.CmdValoresCrit.Clear
    For i = 50 To 100
        Me.CmdValoresCrit.AddItem i & " %"
    Next i
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
End Select
'MSFlexGrid1.SetFocus

Case 2
Me.PicValoresCrit.Width = 4935
Me.PicValoresCrit.Left = 240
Me.PicValoresCrit.Top = 1440
Me.FrmValoresCrit.Width = 4575
Me.CmdValoresCrit.Width = 4335
Me.BtnAceValoresCrit.Left = 2640
Me.BtnAceValoresCrit.Top = 1200
Me.BtnCanValoresCrit.Left = 3720
Me.BtnCanValoresCrit.Top = 1200

Select Case MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Col
Case 0
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Subsectores"
    Me.CmdValoresCrit.Clear
    ' Llena subsectores segun niveles

        Dim Excepciones() As String
        Dim CodDesMod As String
        
        CodModalidad = devuelvecampo("codigos_ensenanza", "", "COD_ENS", "des_ens ='" & Me.Cmb_Cod_ens(Me.MSFlexGrid1.Row - 1) & "'", conn)
        CodDesMod = devuelvecampo("codigos_ensenanza", "", "COD_DES", "cod_ens ='" & CodModalidad & "'", conn)
        rs.CursorLocation = adUseClient
        a = "SELECT *  FROM SUBSECTORES WHERE COD_ENS= '" & CodModalidad & "' AND " & SelcursosM(Me.MSFlexGrid1.Row - 1) & " order by cod_ens asc, ord_asi asc"
        rs.Open a, conn
        If rs.RecordCount > 0 Then
            ReDim Excepciones(rs.RecordCount, 5) As String
            For i = 0 To rs.RecordCount - 1
                Excepciones(i, 0) = rs!cod_sec
                Excepciones(i, 1) = rs!cod_asi
                Excepciones(i, 2) = rs!Cod_Ens
                Excepciones(i, 3) = rs!Nom_Asi
                Excepciones(i, 4) = rs!Num_Gra
                rs.MoveNext
            Next i
        End If

        For i = 0 To rs.RecordCount - 1
            Me.CmdValoresCrit.AddItem " " & Excepciones(i, 4) & "-" & CodDesMod & "  " & Excepciones(i, 3)
        Next i
        ' FIN Llena subsectores segun niveles
        rs.Close
    
    
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True

Case 1
    
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Nota Min. Subsector Def."
    Me.CmdValoresCrit.Clear
    For i = 1 To 7
        For j = 0 To 9
            Me.CmdValoresCrit.AddItem i & "," & j
            If i = 7 Then Exit For
        Next j
    Next i
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
End Select


End Select

End Sub

Public Sub SubItemGrd(NameGrd As Control, fila As Long)
If fila > 1 Then
    NumItem = fila
Else
    NumItem = NameGrd.Rows - 1
End If

If NumItem > 1 Then
    NameGrd.RemoveItem (NumItem)
Else
    For i = 0 To NameGrd.Cols - 1
        NameGrd.TextMatrix(1, i) = ""
    Next i
End If

NameGrd.SetFocus
NameGrd.Col = 0



End Sub

Private Sub BtnAceValoresCrit_Click()
Select Case grilla
Case 1
    Select Case MSFlexGrid1.Col
    Case 1
        Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = CmdValoresCrit.Text
    Case 2
        Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = CmdValoresCrit.Text
    Case 3
        Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = CmdValoresCrit.Text
    Case 4
        Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = CmdValoresCrit.Text
    Case 5
        Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = CmdValoresCrit.Text
    
    End Select
    
MSFlexGrid1.SetFocus

' Revisa si existen celdas en blanco
c = Me.MSFlexGrid1.Cols
f = MSFlexGrid1.Rows
For i = 1 To c - 1
    MSFlexGrid1.Col = i
    If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, i) = "" Then
        Me.FrmNivAplica.Enabled = False
        Me.FrmCodIntervienen.Enabled = False
        Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Enabled = False
        Me.BtnAddGrid1.Enabled = False
        Me.BtnSubGrid1.Enabled = False
        
        Exit For
    Else
        Me.FrmNivAplica.Enabled = True
        Me.BtnAddGrid1.Enabled = True
        Me.BtnSubGrid1.Enabled = True
        
    End If
Next i
Call MSFlexGrid1_Click
' FIN Revisa si existen celdas en blanco

Case 2
    Select Case MSFlexGrid2(MSFlexGrid1.Row - 1).Col
    Case 0
        For i = 1 To Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Rows - 1
            If Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(i, 0) = Me.CmdValoresCrit.Text Then
                MsgBox "Ya existe un subsector " & Me.CmdValoresCrit.Text
                MSFlexGrid2(MSFlexGrid1.Row - 1).SetFocus
                Exit Sub
            End If
        Next i
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(MSFlexGrid2(MSFlexGrid1.Row - 1).Row, MSFlexGrid2(MSFlexGrid1.Row - 1).Col) = CmdValoresCrit.Text
        
        MSFlexGrid2(MSFlexGrid1.Row - 1).SetFocus
    
    Case 1
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(MSFlexGrid2(MSFlexGrid1.Row - 1).Row, MSFlexGrid2(MSFlexGrid1.Row - 1).Col) = CmdValoresCrit.Text
    End Select

    ' Revisa si existen celdas en blanco
    c = Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Cols
    f = MSFlexGrid2(MSFlexGrid1.Row - 1).Rows
    For i = 1 To c - 1
        MSFlexGrid2(MSFlexGrid1.Row - 1).Col = i
        If MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(MSFlexGrid2(MSFlexGrid1.Row - 1).Row, i) = "" Then
            'Me.FrmNivAplica.Enabled = False
            'Me.BtnAddGrid1.Enabled = False
            'Me.BtnSubGrid1.Enabled = False
        
            Exit For
        Else
            'Me.FrmNivAplica.Enabled = True
            'Me.BtnAddGrid1.Enabled = True
            'Me.BtnSubGrid1.Enabled = True
            
        End If
    Next i
    Call MSFlexGrid2_Click(MSFlexGrid1.Row - 1)
    ' FIN Revisa si existen celdas en blanco
    
End Select
'********************************************************************
' reviza si hay celdas en blanco antes hacer BtnGraCri.Enabled =true
  Call HabilitarGrbar
'********************************************************************
End Sub
Private Sub BtnAddGrid1_Click()
Me.PicValoresCrit.Visible = False
c = Me.MSFlexGrid1.Cols
f = MSFlexGrid1.Rows
For i = 1 To c - 1
    MSFlexGrid1.Col = i
    If MSFlexGrid1.Text = "" Then
        MsgBox "No puede agregar más filas si hay celdas en blanco", vbExclamation + vbOKOnly, "Mensaje de Gescol"
        MSFlexGrid1.Row = f - 1
        MSFlexGrid1.SetFocus
        Exit Sub
    End If
Next i
Call AddItemGrd(MSFlexGrid1)
MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 0) = FillconCero(MSFlexGrid1.Rows - 1, 3)
Me.MSFlexGrid1.Col = 0
' Crea matriz de controles
' Nivel en que se aplica
Load Cmb_Cod_ens(MSFlexGrid1.Rows - 2)
Load Me.lst_niveles(MSFlexGrid1.Rows - 2)
Load chk_todos_niveles(MSFlexGrid1.Rows - 2)

'Cmb_Cod_ens(MSFlexGrid1.Rows - 2).Clear
Call llenacombo(Me.Cmb_Cod_ens(MSFlexGrid1.Rows - 2), "codigos_ensenanza ce", "distinct ce.des_ens", "", conn)
Me.Cmb_Cod_ens(MSFlexGrid1.Rows - 2).ListIndex = 1
Cmb_Cod_ens(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
lst_niveles(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
chk_todos_niveles(MSFlexGrid1.Rows - 2 - 1).Visible = False  'oculta el control anteriior

Cmb_Cod_ens(MSFlexGrid1.Rows - 2).Visible = True
lst_niveles(MSFlexGrid1.Rows - 2).Visible = True
chk_todos_niveles(MSFlexGrid1.Rows - 2).Visible = True

'Codigos que intervienen
Load lst_DecProm(MSFlexGrid1.Rows - 2)
lst_DecProm(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
lst_DecProm(MSFlexGrid1.Rows - 2).Visible = True
Load chk_Todos_cod(MSFlexGrid1.Rows - 2)
chk_Todos_cod(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
chk_Todos_cod(MSFlexGrid1.Rows - 2).Visible = True
' Excepciones
Load chkNingunaExc(MSFlexGrid1.Rows - 2)
chkNingunaExc(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
EntroChkNingunaExc = "SI"
chkNingunaExc(MSFlexGrid1.Rows - 2) = False
EntroChkNingunaExc = "NO"
chkNingunaExc(MSFlexGrid1.Rows - 2).Visible = True
Load MSFlexGrid2(MSFlexGrid1.Rows - 2)
MSFlexGrid2(MSFlexGrid1.Rows - 2 - 1).Visible = False 'oculta el control anteriior
MSFlexGrid2(MSFlexGrid1.Rows - 2).Visible = True
' Fin Crea matriz de controles
 ReDim Preserve SelcursosM(MSFlexGrid1.Rows - 2) ' Matriz de niveles seleccionados
End Sub

Private Sub BtnCanCri_Click()
Unload Me
End Sub

Private Sub BtnCanValoresCrit_Click()
Me.PicValoresCrit.Visible = False
End Sub

Private Sub BtnGraCri_Click()
If MsgBox("¿Desea guardar los cambios?", vbYesNo + vbQuestion) = vbNo Then Exit Sub
'borra todos los registros de todas las tablas --> graba a l final
        conn.Execute "delete from CRITERIOS"
        conn.Execute "delete from EXCEPCIONES_CRIT"
        conn.Execute "delete from DECRETOS_CRIT"
' FIN borra todos los registros de todas las tablas --> graba a l final

Dim NivelesCrit As String
For i = 1 To Me.MSFlexGrid1.Rows - 1
' Niveles crit
CodModalidad = devuelvecampo("codigos_ensenanza", "", "COD_ENS", "des_ens ='" & Me.Cmb_Cod_ens(i - 1) & "'", conn)
NivelesCrit = ""
For t = 0 To Me.lst_niveles(i - 1).ListCount - 1
    If Me.lst_niveles(i - 1).Selected(t) Then
        NivelesCrit = NivelesCrit & Me.lst_niveles(i - 1).List(t) & "1"
    Else
        NivelesCrit = NivelesCrit & Me.lst_niveles(i - 1).List(t) & "0"
    End If
Next t
NivelesCrit = CodModalidad & NivelesCrit
' FIN Niveles crit


    'If Not ExistReg("criterios", "cod_crit ='" & i & "'") Then
        ' No hace nada aqui --> graba a l final
    'Else
        ' SI Existe borra todos los registros de todas las tablas --> graba a l final
        'conn.Execute "UPDATE CRITERIOS Set NUM_NOTAS_DEF = '" & MSFlexGrid1.TextMatrix(i, 1) & "', NOTA_RAMO_DEF = '" & MSFlexGrid1.TextMatrix(i, 2) & "', PROM_FIN = '" & MSFlexGrid1.TextMatrix(i, 3) & "', PROM_AUTO = '" & MSFlexGrid1.TextMatrix(i, 4) & "', ASIS_CRIT = '" & MSFlexGrid1.TextMatrix(i, 5) & "', NIVELES_CRIT = '" & NivelesCrit & "' WHERE COD_CRIT ='" & i & "'"
    'End If
            
    ' ********* Graba todos los cambios hechos en criterios
    If Me.chkNingunaExc(i - 1) = 1 Then
        exc = 0
    Else
        exc = 1
    End If
    conn.Execute "INSERT INTO CRITERIOS(COD_CRIT, NUM_NOTAS_DEF, NOTA_RAMO_DEF, PROM_FIN, PROM_AUTO, ASIS_CRIT, NIVELES_CRIT, EXC_CRIT) values('" & FillconCero(MSFlexGrid1.TextMatrix(i, 0), 3) & "', '" & MSFlexGrid1.TextMatrix(i, 1) & "', '" & MSFlexGrid1.TextMatrix(i, 2) & "', '" & MSFlexGrid1.TextMatrix(i, 3) & "', '" & MSFlexGrid1.TextMatrix(i, 4) & "', '" & MSFlexGrid1.TextMatrix(i, 5) & "', '" & NivelesCrit & "', '" & exc & "')"
    For s = 1 To Me.MSFlexGrid2(i - 1).Rows - 1
        conn.Execute "INSERT INTO EXCEPCIONES_CRIT(COD_CRIT, COD_EXC, NOM_EXC) values('" & FillconCero(MSFlexGrid1.TextMatrix(i, 0), 3) & "', '" & FillconCero(Trim(str(s)), 2) & "', '" & MSFlexGrid2(i - 1).TextMatrix(s, 0) & MSFlexGrid2(i - 1).TextMatrix(s, 1) & "')"
    Next s
        
    For t = 0 To Me.lst_DecProm(i - 1).ListCount - 1
        If Me.lst_DecProm(i - 1).Selected(t) Then
            conn.Execute "INSERT INTO DECRETOS_CRIT(COD_CRIT, COD_DEC) values('" & FillconCero(MSFlexGrid1.TextMatrix(i, 0), 3) & "', '" & Me.lst_DecProm(i - 1).List(t) & "SI" & "')"
        Else
            conn.Execute "INSERT INTO DECRETOS_CRIT(COD_CRIT, COD_DEC) values('" & FillconCero(MSFlexGrid1.TextMatrix(i, 0), 3) & "', '" & Me.lst_DecProm(i - 1).List(t) & "NO" & "')"
        End If
    Next t
    ' ********* FIN Graba todos los cambios hechos en criterios
Next i


End Sub

Private Sub BtnSubGrid1_Click()

'Pregunta por borrar
If MsgBox("¿Desea Borrar?", vbQuestion + vbYesNo) = vbYes Then


If MSFlexGrid1.Rows > 2 Then

    ' Crea matriz de controles
    ' Nivel en que se aplica
    Unload Cmb_Cod_ens(MSFlexGrid1.Rows - 2)
    Unload Me.lst_niveles(MSFlexGrid1.Rows - 2)
    Unload chk_todos_niveles(MSFlexGrid1.Rows - 2)
    
    'Codigos que intervienen
    Unload lst_DecProm(MSFlexGrid1.Rows - 2)
    Unload chk_Todos_cod(MSFlexGrid1.Rows - 2)
    ' Excepciones
    Unload MSFlexGrid2(MSFlexGrid1.Rows - 2)
    Unload chkNingunaExc(MSFlexGrid1.Rows - 2)
    ' Fin Crea matriz de controles
ReDim Preserve SelcursosM(MSFlexGrid1.Rows - 3) ' Matriz de niveles seleccionados
'SelcursosM(MSFlexGrid1.Rows - 2) = ""
End If

'Call SubItemGrd(Me.MSFlexGrid1, MSFlexGrid1.Rows - 1)
'Call MSFlexGrid1_Click
If MSFlexGrid1.Rows < 3 Then
    Me.BtnGraCri.Enabled = False
    'Me.cmb_cod_ens(MSFlexGrid1.Rows - 2).ListIndex = 0
    'Me.cmb_cod_ens(MSFlexGrid1.Rows - 2).ListIndex = 1
    'Excepciones
    EntroChkNingunaExc = "SI"
    Me.chkNingunaExc(MSFlexGrid1.Rows - 2).Value = False
    EntroChkNingunaExc = "NO"
    Me.MSFlexGrid2((MSFlexGrid1.Rows - 2)).Clear
    Me.MSFlexGrid2(Me.MSFlexGrid1.Rows - 2).FormatString = "Nombre del Subsector                                                                                               | Nota"
    Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Enabled = False
    Me.Frame2.Enabled = False
    ' Fin Excepciones
    'Niveles
    Me.FrmNivAplica.Enabled = False
    'FIN Niveles
    'Codigos que intervienen
    Call CargaDecProm_Click
    Me.FrmCodIntervienen.Enabled = False
    'Codigos que intervienen
Else
    Me.BtnGraCri.Enabled = True
End If
Call SubItemGrd(Me.MSFlexGrid1, MSFlexGrid1.Rows - 1)
Call MSFlexGrid1_Click
    If MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 0) = "" Then MSFlexGrid1.TextMatrix(MSFlexGrid1.Rows - 1, 0) = "001"

Else
    
End If
'termina borrar

End Sub

Private Sub CargaDecProm_Click()
lst_DecProm(MSFlexGrid1.Row - 1).Clear
Call llenalista(lst_DecProm(MSFlexGrid1.Row - 1), "decretos_eva", "cod_dec", "", conn)
End Sub

Private Sub chk_Todos_cod_Click(Index As Integer)
If Me.chk_Todos_cod(Me.MSFlexGrid1.Row - 1).Value Then
    For t = 0 To Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).ListCount - 1
        Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).Selected(t) = True
    Next t
Else
    For t = 0 To Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).ListCount - 1
        Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).Selected(t) = False
        Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).ListIndex = 0
    Next t
End If

End Sub


Private Sub chk_todos_niveles_Click(Index As Integer)
If Me.chk_todos_niveles(Me.MSFlexGrid1.Row - 1).Value Then
    For t = 0 To Me.lst_niveles(Me.MSFlexGrid1.Row - 1).ListCount - 1
        Me.lst_niveles(Me.MSFlexGrid1.Row - 1).Selected(t) = True
    Next t
Else
    For t = 0 To Me.lst_niveles(Me.MSFlexGrid1.Row - 1).ListCount - 1
        Me.lst_niveles(Me.MSFlexGrid1.Row - 1).Selected(t) = False
        Me.lst_niveles(Me.MSFlexGrid1.Row - 1).ListIndex = 0
    Next t
End If
End Sub




Private Sub chkNingunaExc_Click(Index As Integer)
If EntroChkNingunaExc <> "SI" Then
If Me.chkNingunaExc(MSFlexGrid1.Row - 1) Then
    If MsgBox("Esta acción quitará los subsectores seleccionados si los hay. ¿ Desea continuar ?", vbYesNo + vbQuestion) = vbYes Then
        '******* Borra filas de Grilla 2 (Excepciones)
        For j = 1 To Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Rows - 1
            Call SubItemGrd(Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1), Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Row)
        Next j
        '******* Borra filas de Grilla 2 (Excepciones)
        
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Clear
        Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).FormatString = "Nombre del Subsector                                                                                               | Nota"
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(MSFlexGrid2(MSFlexGrid1.Row - 1).Row, 0) = " --- NINGUNO ---"
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(MSFlexGrid2(MSFlexGrid1.Row - 1).Row, 1) = " --"
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Enabled = False
        Me.Command1.Enabled = False
        Me.Command2.Enabled = False
        Call Me.HabilitarGrbar
    Else
        EntroChkNingunaExc = "SI"
        Me.chkNingunaExc(MSFlexGrid1.Rows - 2).Value = False
        Exit Sub
    End If
Else
    Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Clear
    Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).FormatString = "Nombre del Subsector                                                                                               | Nota"
    Me.Command1.Enabled = True
    Me.Command2.Enabled = True
    Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Enabled = True
    Call Me.HabilitarGrbar
End If
'EntroChkNingunaExc = "SI"
'Exit Sub
End If
EntroChkNingunaExc = "NO"
End Sub


Private Sub Cmb_Cod_ens_Click(Index As Integer)
Me.lst_niveles(Me.MSFlexGrid1.Row - 1).Clear
CodModalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens(MSFlexGrid1.Row - 1).Text & "'", conn)

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "Select distinct num_gra from subsectores where cod_ens = '" & CodModalidad & "' order by num_gra", conn
If rs.RecordCount > 0 Then
    While Not rs.EOF
        Me.lst_niveles(MSFlexGrid1.Row - 1).AddItem rs("num_gra")
        rs.MoveNext
    Wend
End If
rs.Close

End Sub

Private Sub Command1_Click()
Me.PicValoresCrit.Visible = False
c = Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Cols
f = MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Rows
For i = 1 To c - 1
    MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Col = i
    If MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Text = "" Then
        MsgBox "No puede agregar más filas si hay celdas en blanco", vbExclamation + vbOKOnly, "Mensaje de Gescol"
        MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Row = f - 1
        MSFlexGrid2(Me.MSFlexGrid1.Row - 1).SetFocus
        Exit Sub
    End If
Next i
Call AddItemGrd(MSFlexGrid2(Me.MSFlexGrid1.Row - 1))
'Me.MSFlexGrid2.Cols -1

'For i = 0 To Me.CmdValoresCrit.ListCount - 1
'    If Me.CmdValoresCrit.List(i) = MSFlexGrid2.TextMatrix(Me.MSFlexGrid2.Cols - 2, 0) Then Me.CmdValoresCrit.RemoveItem (i)
'Next i


End Sub

Private Sub Command2_Click()

Me.PicValoresCrit.Visible = False
If MsgBox("Se dispone a eliminar la Excepción " & Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).TextMatrix(Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Row, 0) & ". ¿Desea continuar?", vbYesNo + vbQuestion) = vbYes Then Call SubItemGrd(Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1), Me.MSFlexGrid2(Me.MSFlexGrid1.Row - 1).Row)

'reviza si hay celdas en blanco antes avilotar boton grabar
c = Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Cols
f = Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Rows
For i = 1 To c - 1
    Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Col = i
    If Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Text = "" Then
        Me.BtnGraCri.Enabled = False
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Row = f - 1
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).SetFocus
        Exit Sub
    End If
Next i
' FIN reviza si hay celdas en blanco antes avilotar boton grabar

Me.BtnGraCri.Enabled = True

End Sub
Private Sub Form_Load()
Dim NomModalidad As String
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient

CentrarForma Me
MSFlexGrid1.Cols = 6
MSFlexGrid1.Rows = 2
Me.MSFlexGrid1.TextMatrix(1, 0) = "001"
NumItem = 1
ReDim SelcursosM(0)

'********
Set RsAux = New ADODB.Recordset
RsAux.CursorLocation = adUseClient
a = "SELECT * FROM CRITERIOS ORDER BY COD_CRIT"
RsAux.Open a, conn

If RsAux.RecordCount > 0 Then
    Me.MSFlexGrid1.Rows = RsAux.RecordCount + 1
    Me.MSFlexGrid1.Cols = 6
    f = 0

For i = 1 To RsAux.RecordCount - 1
' Crea matriz de controles
' Nivel en que se aplica
Load Cmb_Cod_ens(i)
Load Me.lst_niveles(i)
Load chk_todos_niveles(i)
Cmb_Cod_ens(i).Clear
Call llenacombo(Me.Cmb_Cod_ens(i), "codigos_ensenanza ce", "distinct ce.des_ens", "", conn)
'Me.cmb_cod_ens(MSFlexGrid1.Rows - 2).ListIndex = 1

'Codigos que intervienen
Load lst_DecProm(i)
Load chk_Todos_cod(i)
' Excepciones
Load chkNingunaExc(i)
EntroChkNingunaExc = "SI"
chkNingunaExc(i) = False
EntroChkNingunaExc = "NO"
Load MSFlexGrid2(i)
' Fin Crea matriz de controles
ReDim Preserve SelcursosM(i) ' Matriz de niveles seleccionados
Next i
'*******
    While Not RsAux.EOF
        f = f + 1
        Me.MSFlexGrid1.TextMatrix(f, 0) = RsAux(0)
        Me.MSFlexGrid1.TextMatrix(f, 1) = RsAux(1)
        Me.MSFlexGrid1.TextMatrix(f, 2) = RsAux(2)
        Me.MSFlexGrid1.TextMatrix(f, 3) = RsAux(3)
        Me.MSFlexGrid1.TextMatrix(f, 4) = RsAux(4)
        Me.MSFlexGrid1.TextMatrix(f, 5) = Val(RsAux(5)) & "%"
        NomModalidad = devuelvecampo("codigos_ensenanza", "", "des_ens", "cod_ens ='" & Left(RsAux(6), 3) & "'", conn)
        ' Niveles
        Me.Cmb_Cod_ens(f - 1) = NomModalidad
        Me.lst_niveles(f - 1).Clear
        Niveles = Mid(RsAux(6), 4)
        n = 1
        For i = 1 To Len(Niveles) / 2
            nivel1 = Mid(Niveles, n, 2)
            Me.lst_niveles(f - 1).AddItem Left(nivel1, 1)
            If Right(nivel1, 1) = "1" Then Me.lst_niveles(f - 1).Selected(i - 1) = True
            n = n + 2
        Next i
        ' FIN Niveles
        RsAux.MoveNext
    Wend
    RsAux.Close
    
    Set RsAux = New ADODB.Recordset
    RsAux.CursorLocation = adUseClient
      
        For f = 1 To Me.MSFlexGrid1.Rows - 1
            '******* Codigos qie intervienen ********
            a = "SELECT * FROM decretos_crit where cod_crit ='" & Me.MSFlexGrid1.TextMatrix(f, 0) & "' ORDER BY COD_DEC"
            RsAux.Open a, conn
            If RsAux.RecordCount > 0 Then
                For i = 1 To RsAux.RecordCount
                    Codigo = Right(RsAux(1), 6)
                    Me.lst_DecProm(f - 1).AddItem Left(Codigo, 4)
                    If Right(Codigo, 2) = "SI" Then Me.lst_DecProm(f - 1).Selected(i - 1) = True
                    RsAux.MoveNext
                Next i
            End If
            RsAux.Close
            '******* FIN Codigos qie intervienen ********
            
            '******* Excepciones ********
            a = "SELECT * FROM excepciones_crit where cod_crit ='" & Me.MSFlexGrid1.TextMatrix(f, 0) & "' ORDER BY COD_EXC"
            RsAux.Open a, conn
            If RsAux.RecordCount > 0 Then
                Me.MSFlexGrid2(f - 1).Rows = RsAux.RecordCount + 1
                For i = 1 To RsAux.RecordCount
                    Me.MSFlexGrid2(f - 1).TextMatrix(i, 0) = Mid(RsAux(2), 1, Len(RsAux(2)) - 3)
                    If InStr(Me.MSFlexGrid2(f - 1).TextMatrix(i, 0), "--- NINGUNO ---") > 0 Then
                        EntroChkNingunaExc = "SI"
                        chkNingunaExc(f - 1).Value = 1
                        EntroChkNingunaExc = "NO"
                    End If
                    Me.MSFlexGrid2(f - 1).TextMatrix(i, 1) = Right(RsAux(2), 3)
                    RsAux.MoveNext
                Next i
            End If
            RsAux.Close
            '******* FIN Excepciones ********
        Next f
Me.BtnAddGrid1.Enabled = True
Me.BtnSubGrid1.Enabled = True
Me.FrmNivAplica.Enabled = True
Me.MSFlexGrid1.Row = 1
Me.MSFlexGrid1.Col = 0
Call MSFlexGrid1_Click
'********
Else

'********* Llena combos ****************
Call llenacombo(Me.Cmb_Cod_ens(MSFlexGrid1.Row - 1), "codigos_ensenanza ce", "distinct ce.des_ens", "", conn)
Cmb_Cod_ens(MSFlexGrid1.Row - 1).ListIndex = 1
'-----
Call llenalista(lst_DecProm(MSFlexGrid1.Rows - 2), "decretos_eva", "cod_dec", "", conn)
'********* FIN Llena combos ****************
End If


End Sub

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

Private Sub lst_DecProm_Click(Index As Integer)
    Call Me.HabilitarGrbar
End Sub

Private Sub lst_niveles_Click(Index As Integer)
'*************
CodDesMod = devuelvecampo("codigos_ensenanza", "", "COD_DES", "des_ens ='" & Me.Cmb_Cod_ens(Me.MSFlexGrid1.Row - 1) & "'", conn)

a = Me.lst_niveles(MSFlexGrid1.Row - 1).List(Me.lst_niveles(MSFlexGrid1.Row - 1).ListIndex) & "-" & CodDesMod
For i = 1 To Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Rows - 1
    If Mid(Me.MSFlexGrid2(MSFlexGrid1.Row - 1).TextMatrix(i, 0), 2, 4) = a Then
        If Entro <> "SI" Then
            MsgBox "No es posible desseleccionar este nivel mientras existan subsectores en Excepciones." & Chr(13) & Chr(13) & "Quite los subsectores del nivel " & a & " en Excepciones y vuelva a intentarlo."
            Entro = "SI"
            Me.lst_niveles(MSFlexGrid1.Row - 1).Selected(Me.lst_niveles(MSFlexGrid1.Row - 1).ListIndex) = True
        End If
        Entro = "NO"
        Exit Sub
    End If
Next i
'*************
        
        Me.PicValoresCrit.Visible = False
        SelCursos = ""
        For t = 0 To Me.lst_niveles(Index).ListCount - 1 'Me.MSFlexGrid1.Row - 1
            If Me.lst_niveles(Index).Selected(t) Then 'Me.MSFlexGrid1.Row - 1
                Con = t
            End If
        Next t
        
        For t = 0 To Me.lst_niveles(Index).ListCount - 1 'Me.MSFlexGrid1.Row - 1
            If Me.lst_niveles(Index).Selected(t) Then 'Me.MSFlexGrid1.Row - 1
                If t = Con Then
                    SelCursos = SelCursos & "num_gra = '" & Me.lst_niveles(Index).List(t) & "'" 'Me.MSFlexGrid1.Row - 1
                    Niveles = Niveles & t + 1
                Else
                    SelCursos = SelCursos & "num_gra = '" & Me.lst_niveles(Index).List(t) & "' or " 'Me.MSFlexGrid1.Row - 1
                    Niveles = Niveles & t + 1 & "-"
                End If '{}
            End If
        Next
        If SelCursos = "" Then
            'Me.Frame2.Enabled = False
            Me.CargaDecProm.Enabled = False 'codigos
            Me.lst_DecProm(Index).Enabled = False 'codigos 'Me.MSFlexGrid1.Row - 1
            Me.chk_Todos_cod(Index).Enabled = False ' codigos 'Me.MSFlexGrid1.Row - 1
            Me.MSFlexGrid2(Index).Enabled = False 'Me.MSFlexGrid1.Row - 1
            Me.BtnGraCri.Enabled = False
            Exit Sub
        End If
        
        SelCursos = "(" & SelCursos & ")"
        Frame2.Enabled = True
        Me.MSFlexGrid2(Index).Enabled = True 'Me.MSFlexGrid1.Row - 1
        Me.FrmCodIntervienen.Enabled = True
        Me.CargaDecProm.Enabled = True 'codigos
        Me.lst_DecProm(Index).Enabled = True 'codigos 'Me.MSFlexGrid1.Row - 1
        Me.chk_Todos_cod(Index).Enabled = True ' codigos 'Me.MSFlexGrid1.Row - 1
        
        SelcursosM(Index) = SelCursos
        
        
        Call Me.HabilitarGrbar
End Sub


Private Sub MSFlexGrid1_Click()
grilla = 1
For i = 1 To MSFlexGrid1.Rows - 1
    If i <> MSFlexGrid1.Row Then
        ' Nivel en que se aplica
        lst_niveles(i - 1).Visible = False
        Cmb_Cod_ens(i - 1).Visible = False
        chk_todos_niveles(i - 1).Visible = False
        'Codigos que intervienen
        lst_DecProm(i - 1).Visible = False
        chk_Todos_cod(i - 1).Visible = False
        'Excepciones
        MSFlexGrid2(i - 1).Visible = False
    Else
        ' Nivel en que se aplica
        lst_niveles(i - 1).Visible = True
        Cmb_Cod_ens(i - 1).Visible = True
        chk_todos_niveles(i - 1).Visible = True
        'Codigos que intervienen
        lst_DecProm(i - 1).Visible = True
        chk_Todos_cod(i - 1).Visible = True
        'Excepciones
        MSFlexGrid2(i - 1).Visible = True
    End If
Next i

Call MuestraPicValoresCrit
Me.Frame1.Caption = "Criterio - " & Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0)


End Sub

Private Sub MSFlexGrid1_SelChange()
grilla = 1
For i = 1 To MSFlexGrid1.Rows - 1
    If i <> MSFlexGrid1.Row Then
        ' Nivel en que se aplica
        lst_niveles(i - 1).Visible = False
        Cmb_Cod_ens(i - 1).Visible = False
        chk_todos_niveles(i - 1).Visible = False
        'Codigos que intervienen
        lst_DecProm(i - 1).Visible = False
        chk_Todos_cod(i - 1).Visible = False
        'Excepciones
        Me.chkNingunaExc(i - 1).Visible = False
        MSFlexGrid2(i - 1).Visible = False
    
    Else
        ' Nivel en que se aplica
        lst_niveles(i - 1).Visible = True
        Cmb_Cod_ens(i - 1).Visible = True
        chk_todos_niveles(i - 1).Visible = True
        'Codigos que intervienen
        lst_DecProm(i - 1).Visible = True
        chk_Todos_cod(i - 1).Visible = True
        'Excepciones
        If MSFlexGrid2(i - 1).TextMatrix(1, 0) = " --- NINGUNO ---" Then
            Me.Command1.Enabled = False
            Me.Command2.Enabled = False
        Else
            Me.Command1.Enabled = True
            Me.Command2.Enabled = True
        End If
        Me.chkNingunaExc(i - 1).Visible = True
        MSFlexGrid2(i - 1).Visible = True
    End If
Next i

Call MuestraPicValoresCrit
Me.Frame1.Caption = "Criterio - " & Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0)

End Sub


Private Sub MSFlexGrid2_Click(Index As Integer)
grilla = 2
Call MuestraPicValoresCrit
End Sub

Private Sub MSFlexGrid2_SelChange(Index As Integer)
'Grilla = 2
'Call MuestraPicValoresCrit
grilla = 1
For i = 1 To MSFlexGrid1.Rows - 1
    If i <> MSFlexGrid1.Row Then
        ' Nivel en que se aplica
        lst_niveles(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
        Cmb_Cod_ens(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
        chk_todos_niveles(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
        'Codigos que intervienen
        lst_DecProm(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
        chk_Todos_cod(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
        'Excepciones
        MSFlexGrid2(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = False
    Else
        ' Nivel en que se aplica
        lst_niveles(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
        Cmb_Cod_ens(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
        chk_todos_niveles(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
        'Codigos que intervienen
        lst_DecProm(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
        chk_Todos_cod(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
        'Excepciones
        MSFlexGrid2(Val(Me.MSFlexGrid1.TextMatrix(i, 0)) - 1).Visible = True
    End If
Next i
Call MuestraPicValoresCrit
End Sub

Public Sub HabilitarGrbar()
'********************************************************************
' reviza si hay celdas en blanco antes hacer BtnGraCri.Enabled =true
'********************************************************************
c = Me.MSFlexGrid1.Cols
f = MSFlexGrid1.Rows
For i = 1 To c - 1
    MSFlexGrid1.Col = i
    If MSFlexGrid1.Text = "" Then
        'MsgBox "No puede agregar más filas si hay celdas en blanco", vbExclamation + vbOKOnly, "Mensaje de Gescol"
        Me.BtnGraCri.Enabled = False
        MSFlexGrid1.Row = f - 1
        Exit Sub
    End If
Next i
c = Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Cols
f = Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Rows
For i = 1 To c - 1
    Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Col = i
    If Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Text = "" Then
        'MsgBox "No puede agregar más filas si hay celdas en blanco", vbExclamation + vbOKOnly, "Mensaje de Gescol"
        Me.BtnGraCri.Enabled = False
        Me.MSFlexGrid2(MSFlexGrid1.Row - 1).Row = f - 1
        Exit Sub
    End If
Next i
' codigos de promocion
Dim DecPromSel As Integer
DecPromSel = 0
For t = 0 To Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).ListCount - 1
    If Me.lst_DecProm(Me.MSFlexGrid1.Row - 1).Selected(t) Then
        DecPromSel = DecPromSel + 1
    End If
Next t
If DecPromSel = 0 Then
    Me.BtnGraCri.Enabled = False
    Exit Sub
End If
' FIN codigos de promocion

'************************************************************************
' FIN reviza si hay celdas en blanco antes hacer BtnGraCri.Enabled =true
'************************************************************************
Me.BtnGraCri.Enabled = True

End Sub
