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"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form Form_medidas_cautelares 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Medidas Cautelares"
   ClientHeight    =   7620
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   10995
   Icon            =   "Form_medidas_cautelares.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7620
   ScaleWidth      =   10995
   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          =   735
      Left            =   120
      Picture         =   "Form_medidas_cautelares.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   40
      Top             =   6720
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "Ingreso de medidas cautelares:"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4215
      Left            =   1080
      TabIndex        =   0
      Top             =   1560
      Visible         =   0   'False
      Width           =   8655
      Begin VB.ComboBox cb_permanente 
         Height          =   315
         Left            =   6000
         TabIndex        =   46
         Top             =   1800
         Width           =   2295
      End
      Begin VB.CommandButton btn_cerrar 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   7080
         Picture         =   "Form_medidas_cautelares.frx":2AE98
         Style           =   1  'Graphical
         TabIndex        =   39
         Top             =   3360
         Width           =   1215
      End
      Begin VB.CommandButton cmd_grabar 
         Caption         =   "&Guardar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   5280
         Picture         =   "Form_medidas_cautelares.frx":2B200
         Style           =   1  'Graphical
         TabIndex        =   38
         Top             =   3360
         Width           =   1575
      End
      Begin VB.TextBox txt_observacion 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   1680
         MultiLine       =   -1  'True
         TabIndex        =   22
         Top             =   2520
         Width           =   6615
      End
      Begin MSComCtl2.DTPicker dtp_fecha 
         Height          =   285
         Left            =   1680
         TabIndex        =   20
         Top             =   2160
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   503
         _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          =   91226113
         CurrentDate     =   42342
      End
      Begin VB.TextBox txt_dias_hab 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2400
         TabIndex        =   19
         Text            =   " "
         Top             =   1800
         Width           =   615
      End
      Begin VB.TextBox txt_orden_por 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6000
         TabIndex        =   18
         Top             =   1410
         Width           =   2295
      End
      Begin VB.TextBox txt_tribunal 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6000
         TabIndex        =   17
         Top             =   1080
         Width           =   2295
      End
      Begin VB.ComboBox cb_comuna 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   6000
         TabIndex        =   16
         Top             =   720
         Width           =   2295
      End
      Begin VB.TextBox txt_direccion 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6000
         TabIndex        =   15
         Top             =   360
         Width           =   2295
      End
      Begin VB.TextBox txt_nombres 
         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        =   14
         Top             =   1440
         Width           =   2295
      End
      Begin VB.TextBox txt_ape_mat 
         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        =   13
         Top             =   1080
         Width           =   2295
      End
      Begin VB.TextBox txt_ape_pat 
         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        =   12
         Top             =   720
         Width           =   2295
      End
      Begin VB.TextBox txt_rut 
         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             =   360
         Width           =   1335
      End
      Begin MSComCtl2.DTPicker dtp_fin 
         Height          =   285
         Left            =   6000
         TabIndex        =   43
         Top             =   2160
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   503
         _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          =   91226113
         CurrentDate     =   42342
      End
      Begin VB.Label Label16 
         Caption         =   "Permamente:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4800
         TabIndex        =   45
         Top             =   1800
         Width           =   1095
      End
      Begin VB.Label Label15 
         Caption         =   "Fecha Termino:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4800
         TabIndex        =   44
         Top             =   2160
         Width           =   1335
      End
      Begin VB.Label Label12 
         Caption         =   "DIAS HÁBILES"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3120
         TabIndex        =   23
         Top             =   1800
         Width           =   1095
      End
      Begin VB.Label Label11 
         Caption         =   "Observació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        =   21
         Top             =   2520
         Width           =   1215
      End
      Begin VB.Label Label10 
         Caption         =   "TIEMPO MEDIDA CAUTELAR:"
         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        =   10
         Top             =   1800
         Width           =   2295
      End
      Begin VB.Label Label9 
         Caption         =   "Fecha Inicio:"
         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        =   9
         Top             =   2160
         Width           =   1095
      End
      Begin VB.Label Label8 
         Caption         =   "Orden por:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4800
         TabIndex        =   8
         Top             =   1440
         Width           =   1095
      End
      Begin VB.Label Label7 
         Caption         =   "Tribunal:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   4800
         TabIndex        =   7
         Top             =   1080
         Width           =   975
      End
      Begin VB.Label Label6 
         Caption         =   "Comuna:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   4800
         TabIndex        =   6
         Top             =   720
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "Dirección:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   4800
         TabIndex        =   5
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "Nombres:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   240
         TabIndex        =   4
         Top             =   1440
         Width           =   1335
      End
      Begin VB.Label Label3 
         Caption         =   "Apellido Materno:"
         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        =   3
         Top             =   1080
         Width           =   1455
      End
      Begin VB.Label Label2 
         Caption         =   "Apellido Paterno:"
         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        =   2
         Top             =   720
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "R.U.N."
         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        =   1
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.ListBox lst_Alumnos 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   900
      Left            =   840
      TabIndex        =   25
      Top             =   720
      Visible         =   0   'False
      Width           =   3735
   End
   Begin VB.ListBox lst_Rut 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   900
      Left            =   5280
      TabIndex        =   24
      Top             =   720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.CommandButton cmd_editar 
      Caption         =   "&Editar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   6960
      Picture         =   "Form_medidas_cautelares.frx":2B859
      Style           =   1  'Graphical
      TabIndex        =   37
      Top             =   6720
      Width           =   1215
   End
   Begin VB.CommandButton cmd_nuevo 
      Caption         =   "Nuevo"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   8280
      Picture         =   "Form_medidas_cautelares.frx":2BED0
      Style           =   1  'Graphical
      TabIndex        =   36
      Top             =   6720
      Width           =   1215
   End
   Begin VB.CommandButton cmd_eliminar 
      Caption         =   "Eliminar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   9600
      Picture         =   "Form_medidas_cautelares.frx":2C470
      Style           =   1  'Graphical
      TabIndex        =   35
      Top             =   6720
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Caption         =   "Medidas Cautelares contra las siguientes personas:"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   5055
      Left            =   120
      TabIndex        =   34
      Top             =   1200
      Width           =   10695
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   4665
         Left            =   120
         TabIndex        =   42
         Top             =   240
         Width           =   10455
         _ExtentX        =   18441
         _ExtentY        =   8229
         _Version        =   393216
         Cols            =   6
         FixedCols       =   0
         BackColor       =   16777215
         ForeColorSel    =   16777215
         AllowBigSelection=   0   'False
         FocusRect       =   0
         SelectionMode   =   1
         FormatString    =   ""
         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.CommandButton btn_Ver 
      Caption         =   "Ver"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   6960
      Picture         =   "Form_medidas_cautelares.frx":2CAD3
      Style           =   1  'Graphical
      TabIndex        =   33
      Top             =   120
      Width           =   1215
   End
   Begin VB.CommandButton btnOtroAlumno 
      Caption         =   "Otro Alumno"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   8280
      Picture         =   "Form_medidas_cautelares.frx":2D04A
      Style           =   1  'Graphical
      TabIndex        =   32
      Top             =   120
      Width           =   1215
   End
   Begin VB.CommandButton btn_Cancelar 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   9600
      Picture         =   "Form_medidas_cautelares.frx":2D59F
      Style           =   1  'Graphical
      TabIndex        =   31
      Top             =   120
      Width           =   1215
   End
   Begin VB.Frame Frame_Apo_Caja 
      Caption         =   "Datos del Alumno"
      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        =   26
      Top             =   120
      Width           =   6735
      Begin VB.TextBox txt_RutBusqueda 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   5160
         TabIndex        =   28
         Top             =   360
         Width           =   1335
      End
      Begin VB.TextBox txt_NombreCompleto 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   27
         Top             =   360
         Width           =   3735
      End
      Begin VB.Label Label14 
         Caption         =   "R.u.t."
         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        =   30
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label13 
         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            =   120
         TabIndex        =   29
         Top             =   360
         Width           =   735
      End
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   41
      Top             =   6360
      Width           =   10815
      _ExtentX        =   19076
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
End
Attribute VB_Name = "Form_medidas_cautelares"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub btn_Cancelar_Click()
    Unload Me
End Sub

Private Sub btn_cerrar_Click()
    limpia_controles
    Frame1.Visible = False
    activa_controles
    btn_Ver_Click
End Sub

Private Sub btn_Ver_Click()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset

    var_sql = "SELECT run_mc AS 'R.U.N.',CONCAT(ape_pat_mc,' ',ape_mat_mc,' ',nombres_mc) AS Persona ,dir_mc AS Direccion,comuna,tribunal_mc," _
            & "orden_por_mc,fecha_inicio_mc,dias_hab_mc,observacion_mc,fecha_termino_mc,permanente" _
            & " FROM medidas_cautelares mc,codigos__geograficos cg" _
            & " WHERE mc.comuna_mc = cg.cod_geo AND run_alu_mc = '" & txt_RutBusqueda.Text & "'"
                
    objRS.Open var_sql, 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
End Sub

Private Sub btnOtroAlumno_Click()
    txt_RutBusqueda.Locked = False
    txt_NombreCompleto.Locked = False
    btn_Ver.Enabled = True
    limpia_controles
    'frm_DatosAlumno.Visible = False
    'desabilita_controles
    lst_Rut.Visible = False
    lst_Alumnos.Visible = False
'    msflex_matriculas.Clear
'    msflex_matriculas.Rows = 1
'    mshflex_Apoderados.Clear
'    mshflex_Apoderados.Rows = 1
'    sst_Busqueda.Enabled = False
   ' sst_Busqueda.Tab = 0
    txt_NombreCompleto.Text = ""
    txt_RutBusqueda.Text = ""
    MSFlexGrid1.Clear
    MSFlexGrid1.Rows = 2
    Frame1.Visible = False
   
End Sub


Private Sub cmd_editar_Click()
    'Frame1.Visible = True
    MSFlexGrid1_DblClick
    cmd_grabar.Caption = "Editar"
'    btn_Ver_Click
End Sub

Private Sub cmd_eliminar_Click()
    'Frame1.Visible = True
    MSFlexGrid1_DblClick
    cmd_grabar.Caption = "Eliminar"
    desactiva_controles
    
    
'    btn_Ver_Click
End Sub

Private Sub cmd_grabar_Click()
    Dim var_sql As String
           
    Comuna = DevuelveCampo("codigos__geograficos", "", "cod_geo", "comuna = '" & cb_comuna.Text & "'", conn)
    
    If txt_rut.Text = "" Or txt_ape_pat.Text = "" Or txt_ape_mat.Text = "" Or txt_nombres.Text = "" Or _
    cb_comuna.Text = "" Or txt_tribunal.Text = "" Or txt_orden_por.Text = "" _
    Or txt_dias_hab.Text = "" Or txt_observacion.Text = "" Or txt_direccion.Text = "" Then
        MsgBox "Faltan datos por completar", vbInformation
        Exit Sub
    End If
            
    If cmd_grabar.Caption = "Grabar" Then
    var_sql = "INSERT INTO `medidas_cautelares` (`run_mc`, `ape_pat_mc`, `ape_mat_mc`, `nombres_mc`," _
            & "`dir_mc`, `comuna_mc`, `tribunal_mc`, `orden_por_mc`," _
            & "`fecha_inicio_mc`,fecha_termino_mc, `dias_hab_mc`, `observacion_mc`, `run_alu_mc`,permanente)" _
            & " VALUES('" & txt_rut.Text & "','" & txt_ape_pat.Text & "','" & txt_ape_mat.Text & "','" & txt_nombres.Text & "'," _
            & "'" & txt_direccion.Text & "','" & Comuna & "','" & txt_tribunal.Text & "','" & txt_orden_por.Text & "'," _
            & "'" & Format(dtp_fecha.Value, "yyyy-mm-dd") & "','" & Format(dtp_fin.Value, "yyyy-mm-dd") & "','" _
            & txt_dias_hab.Text & "','" & txt_observacion.Text & "','" & txt_RutBusqueda.Text & "','" & cb_permanente.Text & "');"
    conn.Execute var_sql
    End If
    
    If cmd_grabar.Caption = "Editar" Then
    var_sql = "UPDATE medidas_cautelares SET " _
            & "run_mc = '" & txt_rut.Text & "'," _
            & "ape_pat_mc = '" & txt_ape_pat.Text & "'," _
            & "ape_mat_mc = '" & txt_ape_mat.Text & "'," _
            & "nombres_mc = '" & txt_nombres.Text & "'," _
            & "dir_mc = '" & txt_direccion.Text & "'," _
            & "comuna_mc = '" & Comuna & "'," _
            & "tribunal_mc = '" & txt_tribunal.Text & "'," _
            & "orden_por_mc = '" & txt_orden_por.Text & "'," _
            & "fecha_inicio_mc = '" & Format(dtp_fecha.Value, "yyyy-mm-dd") & "'," _
            & "fecha_termino_mc = '" & Format(dtp_fin.Value, "yyyy-mm-dd") & "'," _
            & "dias_hab_mc = '" & txt_dias_hab.Text & "'," _
            & "observacion_mc = '" & txt_observacion.Text & "'," _
            & "permanente = '" & cb_permanente.Text & "'" _
            & " WHERE run_mc = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) & "'"
    conn.Execute var_sql
    End If
    
    If cmd_grabar.Caption = "Eliminar" Then
    var_sql = "delete from medidas_cautelares WHERE run_mc = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) & "'"
    conn.Execute var_sql
    End If
    
    limpia_controles
    Frame1.Visible = False
    activa_controles
    btn_Ver_Click
    
End Sub

Private Sub cmd_nuevo_Click()
    limpia_controles
    Frame1.Visible = True
    cmd_grabar.Caption = "Grabar"
    
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 = IIf(MSFlexGrid1.TextMatrix(i, j) = "Null", "", MSFlexGrid1.TextMatrix(i, j))
        
        pgbar.Value = i
        Next j
    Next i
            
    ApExcel.Visible = True
    'ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub

Private Sub Form_Load()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    cb_comuna.Clear
    var_sql = "SELECT comuna FROM codigos__geograficos"
    objRS.Open var_sql, conn
    While Not objRS.EOF
        cb_comuna.AddItem objRS("comuna")
        objRS.MoveNext
    Wend
    objRS.Close
    dtp_fecha.Value = Date
    cb_permanente.AddItem "SI"
    cb_permanente.AddItem "NO"
    cb_permanente.Text = "NO"
End Sub

Private Sub lst_Alumnos_dblClick()
    'Dim dig As String
    'dig = digito(lst_Alumnos.ItemData(lst_Alumnos.ListIndex))
    'Dim Rut As String
    Dim varsql As String
    'Rut = lst_Alumnos.ItemData(lst_Alumnos.ListIndex) & "-" & dig
    
    Dim objRS As ADODB.Recordset
    varsql = "SELECT ci_alu" _
           & " FROM postulantes where concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) = '" _
           & lst_Alumnos.Text & "'"

    Set objRS = New ADODB.Recordset
    objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_NombreCompleto.Text = lst_Alumnos.Text
        txt_RutBusqueda.Text = objRS("ci_alu")
    End If
    objRS.Close
    lst_Rut.Clear
    lst_Rut.Visible = False
    If txt_RutBusqueda.Text <> "" And txt_NombreCompleto.Text <> "" Then
        txt_RutBusqueda.Locked = True
        txt_NombreCompleto.Locked = True
    End If
End Sub

Private Sub lst_Alumnos_LostFocus()
    lst_Alumnos.Visible = False
End Sub

Private Sub lst_Rut_DblClick()
    txt_RutBusqueda.Text = lst_Rut.Text
    lst_Rut.Visible = False
    Dim objRS As ADODB.Recordset
    Dim varsql As String
    varsql = "SELECT ape_pat_alu,ape_mat_alu,nom_alu" _
           & " FROM postulantes where ci_alu='" & txt_RutBusqueda.Text & "'"

    Set objRS = New ADODB.Recordset
        objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_NombreCompleto.Text = objRS("ape_pat_alu") & " " & objRS("ape_mat_alu") & " " & objRS("nom_alu")
    End If
    objRS.Close
    lst_Alumnos.Visible = False
    lst_Rut.Clear
    If txt_RutBusqueda.Text <> "" And txt_NombreCompleto.Text <> "" Then
        txt_RutBusqueda.Locked = True
        txt_NombreCompleto.Locked = True
    End If
End Sub

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
            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 MSFlexGrid1_DblClick()
    Dim objRS As ADODB.Recordset
    Dim varsql As String
    Set objRS = New ADODB.Recordset
    varsql = "SELECT run_mc,ape_pat_mc,ape_mat_mc,nombres_mc,comuna_mc,tribunal_mc," _
           & "orden_por_mc,fecha_inicio_mc,fecha_termino_mc,dias_hab_mc,observacion_mc,run_alu_mc,dir_mc" _
           & " From medidas_cautelares" _
           & " WHERE run_mc = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) & "'"
    objRS.Open varsql, conn
    If Not objRS.EOF Then
        'cmd_VerApoderado.Visible = True
        txt_rut.Text = objRS("run_mc")
        txt_ape_pat.Text = objRS("ape_pat_mc")
        txt_ape_mat.Text = objRS("ape_mat_mc")
        txt_nombres.Text = objRS("nombres_mc")
        cb_comuna.Text = DevuelveCampo("codigos__geograficos", "", "comuna", "cod_geo = '" & objRS("comuna_mc") & "'", conn)
        txt_tribunal.Text = objRS("tribunal_mc")
        txt_orden_por.Text = objRS("orden_por_mc")
        dtp_fecha.Value = objRS("fecha_inicio_mc")
        dtp_fin.Value = IIf(IsNull(objRS("fecha_termino_mc")), Date, objRS("fecha_termino_mc"))
        txt_dias_hab.Text = objRS("dias_hab_mc")
        txt_observacion.Text = objRS("observacion_mc")
        txt_direccion.Text = objRS("dir_mc")
       
        'cmd_VerApoderado.Visible = True
        
        cmd_grabar.Caption = "Editar"
        Frame1.Visible = True
    End If
    objRS.Close
    
End Sub

Private Sub txt_NombreCompleto_Change()
    If txt_NombreCompleto.Text <> "" Then
    Dim varsql As String
    'lst_Rut.Visible = False
    Dim objRC As ADODB.Recordset
    Dim rut As Long
    Set objRS = New ADODB.Recordset
    varsql = "SELECT distinct p.CI_ALU,APE_PAT_ALU,APE_MAT_ALU,NOM_ALU" _
           & " FROM postulantes p,matriculas m" _
           & " where concat(APE_PAT_ALU,' ',ape_mat_alu,' ',nom_alu) LIKE '" & txt_NombreCompleto.Text & "%'" _
           & " and p.ci_alu = m.ci_alu" _
           & " order by ape_pat_alu,ape_mat_alu,nom_alu"
    objRS.Open varsql, conn
    lst_Alumnos.Clear
    If Not objRS.EOF Then
        lst_Alumnos.Visible = True
    End If
    While Not objRS.EOF
        lst_Alumnos.AddItem objRS("APE_PAT_ALU") & " " & objRS("APE_MAT_ALU") & " " & objRS("NOM_ALU")
        rut = Mid(objRS("CI_ALU"), 1, 8)
        lst_Alumnos.ItemData(lst_Alumnos.NewIndex) = rut
        objRS.MoveNext
    Wend
    objRS.Close
    End If
End Sub
Private Sub txt_NombreCompleto_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txt_RutBusqueda_Change()
    If txt_RutBusqueda.Text <> "" Then
    Dim varsql As String
    lst_Rut.Visible = False
    lst_Alumnos.Visible = False
    Dim objRC As ADODB.Recordset
    Dim rut As Long
    Set objRS = New ADODB.Recordset
    varsql = "SELECT distinct m.CI_ALU" _
           & " FROM postulantes p,matriculas m" _
           & " where p.CI_ALU LIKE '" & txt_RutBusqueda & "%'" _
           & " and p.ci_alu = m.ci_alu"
    objRS.Open varsql, conn
    lst_Rut.Clear
    If Not objRS.EOF Then
        lst_Rut.Visible = True
    End If
    While Not objRS.EOF
        lst_Rut.AddItem objRS("CI_ALU")
        objRS.MoveNext
    Wend
    objRS.Close
    End If
End Sub

Public Sub limpia_controles()
     
        txt_rut.Text = ""
        txt_ape_pat.Text = ""
        txt_ape_mat.Text = ""
        txt_nombres.Text = ""
        cb_comuna.Text = ""
        txt_tribunal.Text = ""
        txt_orden_por.Text = ""
        dtp_fecha.Value = Date
        txt_dias_hab.Text = ""
        txt_observacion.Text = ""
        txt_direccion.Text = ""
        dtp_fin.Value = Date
        cb_permanente.Text = "NO"
 
End Sub

Private Sub desactiva_controles()
   
    txt_rut.Enabled = False
    txt_ape_pat.Enabled = False
    txt_ape_mat.Enabled = False
    txt_nombres.Enabled = False
    cb_comuna.Enabled = False
    txt_tribunal.Enabled = False
    txt_orden_por.Enabled = False
    dtp_fecha.Enabled = False
    txt_dias_hab.Enabled = False
    txt_observacion.Enabled = False
    txt_direccion.Enabled = False
    dtp_fin.Enabled = False
    cb_permanente.Enabled = False
End Sub

Private Sub activa_controles()
    txt_rut.Enabled = True
    txt_ape_pat.Enabled = True
    txt_ape_mat.Enabled = True
    txt_nombres.Enabled = True
    cb_comuna.Enabled = True
    txt_tribunal.Enabled = True
    txt_orden_por.Enabled = True
    dtp_fecha.Enabled = True
    txt_dias_hab.Enabled = True
    txt_observacion.Enabled = True
    txt_direccion.Enabled = True
    dtp_fin.Enabled = True
    cb_permanente.Enabled = True
End Sub
