VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_busqueda_cheques 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Busqueda de cheques"
   ClientHeight    =   7740
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   13380
   Icon            =   "Form_busqueda_cheques.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7740
   ScaleWidth      =   13380
   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            =   1680
      Picture         =   "Form_busqueda_cheques.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   16
      Top             =   6360
      Width           =   1575
   End
   Begin VB.CommandButton cmd_salir 
      Caption         =   "Salir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   10080
      Picture         =   "Form_busqueda_cheques.frx":2AE98
      Style           =   1  'Graphical
      TabIndex        =   15
      Top             =   6360
      Width           =   1575
   End
   Begin VB.ListBox lst_ctacte 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   8040
      TabIndex        =   10
      Top             =   600
      Visible         =   0   'False
      Width           =   1935
   End
   Begin VB.ListBox lst_rut_apo 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   5880
      TabIndex        =   1
      Top             =   600
      Visible         =   0   'False
      Width           =   1095
   End
   Begin VB.ListBox lst_nom_apo 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   840
      TabIndex        =   0
      Top             =   600
      Visible         =   0   'False
      Width           =   4215
   End
   Begin VB.Frame Frame3 
      Caption         =   "Listado de Cheques"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4575
      Left            =   120
      TabIndex        =   12
      Top             =   1200
      Width           =   13095
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid 
         Height          =   4215
         Left            =   120
         TabIndex        =   13
         Top             =   240
         Width           =   12855
         _ExtentX        =   22675
         _ExtentY        =   7435
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Frame Frame5 
      Caption         =   "Seleccion por Titular"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   975
      Left            =   120
      TabIndex        =   2
      Top             =   0
      Width           =   13095
      Begin VB.TextBox txt_ctacte 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   7920
         TabIndex        =   9
         Top             =   360
         Width           =   1935
      End
      Begin VB.CommandButton cmd_limpiar 
         Caption         =   "Limpiar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   615
         Left            =   12000
         Picture         =   "Form_busqueda_cheques.frx":2B4BE
         Style           =   1  'Graphical
         TabIndex        =   8
         Top             =   240
         Width           =   735
      End
      Begin VB.CommandButton Btn_Ver_Apoderado 
         Caption         =   "Ver"
         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          =   615
         Left            =   10920
         Picture         =   "Form_busqueda_cheques.frx":2BA5E
         Style           =   1  'Graphical
         TabIndex        =   5
         Top             =   240
         Width           =   735
      End
      Begin VB.TextBox txt_rut_apo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   5760
         TabIndex        =   4
         Top             =   360
         Width           =   1095
      End
      Begin VB.TextBox txt_nom_apo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   3
         Top             =   360
         Width           =   4215
      End
      Begin VB.Label Label1 
         Caption         =   "Cta.Cte."
         BeginProperty Font 
            Name            =   "Arial Narrow"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7320
         TabIndex        =   11
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label8 
         Caption         =   "Run"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   5400
         TabIndex        =   7
         Top             =   360
         Width           =   495
      End
      Begin VB.Label Label7 
         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        =   6
         Top             =   360
         Width           =   615
      End
   End
   Begin MSComctlLib.ProgressBar progreso 
      Height          =   375
      Left            =   120
      TabIndex        =   14
      Top             =   5880
      Width           =   13095
      _ExtentX        =   23098
      _ExtentY        =   661
      _Version        =   393216
      Appearance      =   1
      Max             =   1
      Scrolling       =   1
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   17
      Top             =   7320
      Width           =   13095
      _ExtentX        =   23098
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
End
Attribute VB_Name = "Form_busqueda_cheques"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim fra, fna, frp, fnp As Boolean

Private Sub Btn_Ver_Apoderado_Click()
    If (txt_nom_apo.Text <> "" And txt_rut_apo.Text <> "") Or txt_ctacte.Text <> "" Then
        'bloquear_opciones
        grid.Clear
        grid.Rows = 2
        grid.Cols = 2
        llena_grilla_con_cheques
    Else
        MsgBox "Para realizar la busqueda primero debe seleccionar un criterio", vbInformation
    End If
End Sub

Private Sub cmd_limpiar_Click()
    limpiar
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

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

         For j = 1 To grid.Cols - 1
            ApExcel.Cells((i + 1), j).Formula = IIf(grid.TextMatrix(i, j) = "Null", "", grid.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 lst_ctacte_Click()
    Dim RC As ADODB.Recordset
    txt_ctacte.Text = lst_ctacte.Text
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = False
    lst_ctacte.Visible = False
   ' Set RC = New ADODB.Recordset
'    RC.Open "SELECT run_titular FROM `fnza_cheques_recibidos` where nom_titular = '" & txt_nom_apo.Text & "' ORDER BY nom_titular;", conn
'    RC.MoveFirst
    Flag_sub = True
'    txt_rut_apo.Text = RC("run_titular")
    Flag_sub = False
    Btn_Ver_Apoderado.Enabled = True
   ' RC.Close
'    If txt_nom_apo.Text <> "" And txt_rut_apo.Text <> "" Then
'        txt_nom_apo.Locked = True
'        txt_rut_apo.Locked = True
'    End If
End Sub

Private Sub lst_nom_apo_Click()
    Dim RC As ADODB.Recordset
    txt_nom_apo.Text = lst_nom_apo.Text
    lst_nom_apo.Visible = False
    lst_rut_apo.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT run_titular FROM `fnza_cheques_recibidos` where nom_titular = '" & txt_nom_apo.Text & "' ORDER BY nom_titular;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_rut_apo.Text = RC("run_titular")
    Flag_sub = False
    Btn_Ver_Apoderado.Enabled = True
    RC.Close
    If txt_nom_apo.Text <> "" And txt_rut_apo.Text <> "" Then
        txt_nom_apo.Locked = True
        txt_rut_apo.Locked = True
    End If
End Sub

Private Sub lst_rut_apo_Click()
    Dim RC As ADODB.Recordset
    txt_rut_apo.Text = lst_rut_apo.Text
    lst_rut_apo.Visible = False
    lst_nom_apo.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT nom_titular as nombre_apo FROM fnza_cheques_recibidos where run_titular='" & txt_rut_apo.Text & "' ORDER BY run_titular;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_nom_apo.Text = RC("nombre_apo")
    Flag_sub = False
    Btn_Ver_Apoderado.Enabled = True
    RC.Close
    If txt_nom_apo.Text <> "" And txt_rut_apo.Text <> "" Then
        txt_nom_apo.Locked = True
        txt_rut_apo.Locked = True
    End If
End Sub

Private Sub Text1_Change()

End Sub

Private Sub txt_ctacte_Change()
  
    
If fnp = True Then
    Dim var_sql As String
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    'If txt_nom_apo.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
        
    var_sql = "SELECT cta_cte FROM fnza_cheques_recibidos WHERE cta_cte LIKE '%" & txt_ctacte.Text & "%'"
            
    RC.Open var_sql, conn
    lst_ctacte.Clear
    While Not (RC.EOF)
        lst_ctacte.AddItem RC("cta_cte")
        RC.MoveNext
    Wend
    RC.Close
    Btn_Ver_Apoderado.Enabled = False
    lst_ctacte.Visible = True
    lst_rut_apo.Visible = False
    lst_nom_apo.Visible = False
End If
    
End Sub

Private Sub txt_ctacte_Click()
    fra = False
    fna = False
    frp = False
    fnp = True
End Sub

Private Sub txt_nom_apo_Change()
If fna = True Then
    Dim var_sql As String
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If txt_nom_apo.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
        
    var_sql = "SELECT DISTINCT nom_titular" _
            & " FROM apoderados a, fnza_cheques_recibidos fcr" _
            & " where a.rut_apo = fcr.run_apo and" _
            & " nom_titular" _
            & " like '" & txt_nom_apo.Text & "%'"
            
    RC.Open var_sql, conn
    lst_nom_apo.Clear
    While Not (RC.EOF)
        lst_nom_apo.AddItem RC("nom_titular")
        RC.MoveNext
    Wend
    RC.Close
    Btn_Ver_Apoderado.Enabled = False
    lst_nom_apo.Visible = True
    lst_rut_apo.Visible = False
End If
End Sub

Private Sub txt_nom_apo_Click()
    fra = False
    fna = True
    frp = False
    fnp = False
End Sub

Private Sub txt_rut_apo_Change()
If fra = True Then
    If Flag_sub Then Exit Sub
    If txt_rut_apo.Text = "" Then Exit Sub
    Dim Str_Query As String
    Dim RC As ADODB.Recordset
    
    Set RC = New ADODB.Recordset
    Str_Query = "select distinct run_titular from fnza_cheques_recibidos" _
              & " where run_titular like '" & txt_rut_apo.Text & "%'"
    RC.Open Str_Query, conn
    lst_rut_apo.Clear
    While Not (RC.EOF)
        lst_rut_apo.AddItem RC("run_titular")
        RC.MoveNext
    Wend
    RC.Close
    Btn_Ver_Apoderado.Enabled = False
    lst_rut_apo.Visible = True
    lst_nom_apo.Visible = False
End If
End Sub

Private Sub txt_rut_apo_Click()
   fra = True
    fna = False
    frp = False
    fnp = False
End Sub

Public Sub limpiar()
'    Option1(0).Enabled = True
'    Option1(1).Enabled = True
    'Option1(2).Enabled = True
    
   ' lbl_datos.Visible = False
   ' cb_datos.Visible = False
    'lst_nom_alu.Visible = False
   ' lst_rut_alu.Visible = False
'    lst_nom_apo.Visible = False
'    lst_rut_apo.Visible = False
    
  '  txt_nom_alu.Text = ""
  '  txt_rut_alu.Text = ""
    txt_rut_apo.Text = ""
    txt_nom_apo.Text = ""
    txt_ctacte.Text = ""
    'grid.Rows = 2
    'grid.ClearStructure
    
   ' Frame1.Enabled = True
   ' Btn_Ver_Alumno.Enabled = True
   ' cb_agno_alu.Locked = False
 '   txt_nom_alu.Locked = False
  '  txt_rut_alu.Locked = False
    Btn_Ver_Apoderado.Enabled = True
   ' cb_agno_apo.Locked = False
    txt_nom_apo.Locked = False
    txt_rut_apo.Locked = False
    txt_ctacte.Locked = False
    grid.Rows = 1
End Sub

Public Sub llena_grilla_con_cheques()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql, condicion, Cod_Ens As String
        
 '   If Option1(0).Value = True Then
'        condicion = " and fcr.run_apo = '" & txt_rut_apo.Text & "'" _
'                  & " and date_format(chq_fecha,'%Y') = " & cb_agno_apo.Text
        'condicion = " and DATE_FORMAT(chq_fecha,'%Y-%m-%d') >= '" & Format(dtp_inicio.Value, "yyyy-mm-dd") & "' and DATE_FORMAT(chq_fecha,'%Y-%m-%d') <= '" & Format(dtp_fin.Value, "yyyy-mm-dd") & "'"
'        condicion = "AND run_titular = '" & txt_rut_apo.Text & "'"
'        txt_ctacte
    
    If txt_rut_apo.Text <> "" And txt_ctacte.Text <> "" Then
        condicion = " AND run_titular = '" & txt_rut_apo.Text & "' and cta_cte = '" & txt_ctacte.Text & "'"
    End If
   
    If txt_rut_apo.Text <> "" And txt_ctacte.Text = "" Then
        condicion = " AND run_titular = '" & txt_rut_apo.Text & "'"
    End If
    
    If txt_rut_apo.Text = "" And txt_ctacte.Text <> "" Then
        condicion = " and cta_cte = '" & txt_ctacte.Text & "'"
    End If
        
    If txt_rut_apo.Text = "" And txt_ctacte.Text = "" Then
        MsgBox "No se han seleccionado criterios de busqueda", vbInformation
        Exit Sub
    End If
        
  '  End If
    
'    If Option1(1).Value Then
'        condicion = " and fcr.run_titular = '" & txt_rut_apo.Text & "'" _
'                  & " and date_format(chq_fecha,'%Y') = " & cb_agno_apo.Text
'       ' condicion = " and chq_fecha >= '" & Format(dtp_inicio.Value, "yyyy-mm-dd") & "' and chq_fecha <= '" & Format(dtp_fin.Value, "yyyy-mm-dd") & "'"
'    End If
    
'    var_sql = "SELECT folio_chq,cta_cte as 'Cta. Cte.'," _
'            & "concat(chq_serie,' ',chq_numero) as 'Numero Cheque'," _
'            & "monto_chq as 'Monto',chq_fecha as 'Fecha'," _
'            & "run_titular as 'Rut.Tit.',nom_titular as 'Titular'," _
'            & "estado as 'Estado'" _
'            & " FROM fnza_cheques_recibidos fcr,fnza_estados_cheques fcec" _
'            & " Where fcr.cod_estado = fcec.cod_est" & condicion
            
'    var_sql = "SELECT folio_chq,cta_cte AS 'Cta. Cte.',numero_cheque AS 'Numero Cheque',monto_chq AS 'Monto',chq_fecha AS 'Fecha',run_titular AS 'Rut.Tit.'," _
'            & "nom_titular AS 'Titular',che.estado AS 'Estado',if(factoring is null,'',factoring) AS Factoring,if(d.estado is null,'',d.estado) AS Devuelto FROM" _
'            & " (SELECT c.*,factoring FROM" _
'            & " (SELECT folio_chq,cta_cte,CONCAT(chq_serie,' ',chq_numero) AS Numero_Cheque,monto_chq,chq_fecha,run_titular," _
'            & "nom_titular,estado,cod_factoring,cod_devuelto FROM fnza_cheques_recibidos fcr,fnza_estados_cheques fcec" _
'            & " WHERE fcr.cod_estado = fcec.cod_est " & condicion & ") AS c" _
'            & " Left Join fnza_factoring f" _
'            & " ON c.cod_factoring = f.cod_fac) AS che LEFT JOIN fnza_codigos_cheque_devuelto d ON che.cod_devuelto = d.cod_est"
            
'    var_sql = " SELECT folio_chq,run_titular AS 'Rut Deudor',nom_titular AS 'Nombre Deudor',descripcion AS BANCO,numero_cheque AS '# Cheque'," _
'            & "verificacion AS 'Verif.',banco_plaza AS 'B.y Plaza',cta_cte AS 'Cuenta Cte.'," _
'            & "DATE_FORMAT(chq_fecha,'%d-%M-%Y') AS 'Fecha',monto_chq AS 'Monto',che.estado AS 'Estado'," _
'            & "IF(factoring IS NULL,'',factoring) AS Factoring,IF(d.estado IS NULL,'',d.estado) AS Devuelto,'NO' as MARCAR" _
'            & " FROM (SELECT c.*,factoring FROM (" _
'            & " SELECT folio_chq,cta_cte,chq_numero AS Numero_Cheque,verificacion,banco_plaza,descripcion," _
'            & "monto_chq , chq_fecha, run_titular, nom_titular, Estado, cod_factoring, cod_devuelto" _
'            & " FROM fnza_cheques_recibidos fcr,fnza_estados_cheques fcec,fnza_cod_banco fcb" _
'            & " WHERE fcr.banco = fcb.banco AND fcr.cod_estado = fcec.cod_est " _
'            & condicion _
'            & ") AS c LEFT JOIN fnza_factoring f ON c.cod_factoring = f.cod_fac) AS che" _
'            & " LEFT JOIN fnza_codigos_cheque_devuelto d ON che.cod_devuelto = d.cod_est"
                         
    var_sql = "SELECT folio_chq,run_apo AS 'Rut. Apo.',run_titular AS 'Rut. Tit.',nom_titular AS 'Titular',tel_titular AS 'Tel. Tit.',descripcion AS BANCO,chq_serie AS Serie,numero_cheque AS '# Cheque'," _
            & "verificacion AS 'Verif.',banco_plaza AS 'B.y Plaza',cta_cte AS 'Cuenta Cte.',DATE_FORMAT(chq_fecha,'%d-%M-%Y') AS 'Fecha Venc.'," _
            & "monto_chq AS 'Monto',che.estado AS 'Estado',IF(factoring IS NULL,'',factoring) AS Factoring,IF(d.estado IS NULL,'',d.estado) AS Devuelto," _
            & "DATE_FORMAT(fecha_factoring,'%d-%M-%Y %h:%i %p') AS fecha_factoring FROM (SELECT c.*,factoring FROM ( SELECT run_apo,folio_chq,cta_cte,chq_numero AS Numero_Cheque,chq_serie,tel_titular,verificacion,banco_plaza,descripcion," _
            & "monto_chq , chq_fecha, run_titular, nom_titular, Estado, cod_factoring, cod_devuelto,fecha_factoring FROM fnza_cheques_recibidos fcr,fnza_estados_cheques fcec,fnza_cod_banco fcb" _
            & " Where fcr.banco = fcb.banco And fcr.cod_estado = fcec.cod_est" _
            & condicion & _
            ") AS c LEFT JOIN fnza_factoring f ON c.cod_factoring = f.cod_fac) AS che" _
            & " LEFT JOIN fnza_codigos_cheque_devuelto d ON che.cod_devuelto = d.cod_est"
                         
                             
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        progreso.Min = 0
        progreso.Max = objRS.RecordCount
'        grid.Cols = 2
'        grid.Rows = 2
        If grid.TextMatrix(1, 1) = "" Then
            Call Rec2Grid(objRS, grid, True)
        Else
            
             'If objRS.RecordCount > 0 Then
              '    Call Rec2Grid(objRS, MSFlexGrid1, True)
                ' msflex_alumnos.ColSel = 5
                filas = grid.Rows
                While Not objRS.EOF
                    filas = filas + 1
                    grid.Rows = grid.Rows + 1
                    grid.TextMatrix(filas - 1, 0) = (filas - 1)
                    grid.TextMatrix(filas - 1, 1) = objRS(0)
                    grid.TextMatrix(filas - 1, 2) = objRS(1)
                    grid.TextMatrix(filas - 1, 3) = objRS(2)
                    grid.TextMatrix(filas - 1, 4) = objRS(3)
                    grid.TextMatrix(filas - 1, 5) = objRS(4)
                    grid.TextMatrix(filas - 1, 6) = objRS(5)
                    grid.TextMatrix(filas - 1, 7) = objRS(6)
                    grid.TextMatrix(filas - 1, 8) = objRS(7)
                    grid.TextMatrix(filas - 1, 9) = objRS(8)
                    grid.TextMatrix(filas - 1, 10) = objRS(9)
                    grid.TextMatrix(filas - 1, 11) = objRS(10)
                    grid.TextMatrix(filas - 1, 12) = objRS(11)
                    grid.TextMatrix(filas - 1, 13) = objRS(12)
                    grid.TextMatrix(filas - 1, 14) = objRS(13)
                    objRS.MoveNext
                Wend
'            Else
'                MsgBox "No se ha registrado asistencia este dia en " & colegios2(j), vbInformation
'            End If
'            objRS.Close
            
        End If
        grid.ColWidth(1) = 0
        grid.ColWidth(2) = 950
        grid.ColWidth(3) = 1000
        grid.ColWidth(4) = 1500
        grid.ColSel = 8
    Else
        MsgBox "La busqueda no devolvio resultados", vbInformation
    End If
    objRS.Close
End Sub

Private Sub Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.ClearStructure
    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
