VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3735
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7380
   LinkTopic       =   "Form1"
   ScaleHeight     =   3735
   ScaleWidth      =   7380
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1 
      Height          =   285
      Left            =   1560
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   360
      Width           =   1815
   End
   Begin VB.ListBox List1 
      Height          =   840
      Left            =   1560
      TabIndex        =   3
      Top             =   600
      Width           =   1815
   End
   Begin VB.TextBox Text2 
      Height          =   285
      Left            =   4440
      TabIndex        =   2
      Text            =   "Text2"
      Top             =   360
      Width           =   2055
   End
   Begin VB.ListBox List2 
      Height          =   840
      Left            =   4440
      TabIndex        =   1
      Top             =   600
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "LIMPIAR"
      Height          =   615
      Left            =   4680
      TabIndex        =   0
      Top             =   2280
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "Rut"
      Height          =   255
      Left            =   3840
      TabIndex        =   6
      Top             =   360
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "Nombre"
      Height          =   255
      Left            =   0
      TabIndex        =   5
      Top             =   360
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_Sub As Boolean
Dim Colegio As String
Dim rc As ADODB.Recordset
Dim CMD As ADODB.Command

Private Sub Command1_Click()
Text1.SetFocus
Text1.Text = Empty
Text2.Text = Empty
End Sub
Private Sub Form_Load()
    Flag_Sub = True
    Text1.Text = ""
    Text2.Text = ""
    Flag_Sub = False
    List1.Visible = False
    List2.Visible = False
          
    Set rc = New ADODB.Recordset
    
  End Sub
'Private Sub List1_Click()
    'Text1.Text = List1.Text
    'List1.Visible = False
    'List2.Visible = False
    'rc.CursorLocation = adUseClient
    'rc.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    'rc.MoveFirst
    'Flag_Sub = True
    'Text2.Text = rc("rut_apo")
    'rc.Close
    'Flag_Sub = False
    'Call SeteaGrilla
    'Call LlenaGrilla
'End Sub


Private Sub List2_Click()
Text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    rc.CursorLocation = adUseClient
    rc.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Text2.Text & "' ORDER BY rut_apo;", conn
    rc.MoveFirst
    Flag_Sub = True
    Text1.Text = rc("nombre_apo")
    rc.Close
    Flag_Sub = False
   
End Sub
Private Sub Text1_Change()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    rc.CursorLocation = adUseClient
    List1.Clear
    rc.Open "SELECT DISTINCT a.ape1_apo, a.ape2_apo, a.noms_apo FROM apoderados a, fnza_mensualidad fm where left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    While Not (rc.EOF)
        List1.AddItem rc("ape1_apo") & " " & rc("ape2_apo") & " " & rc("noms_apo")
        rc.MoveNext
    Wend
    rc.Close
    List1.Visible = True
    List2.Visible = False
End Sub

Private Sub Text2_Change()
 ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    If Text2.Text = "" Then Exit Sub
    
    Dim Str_Query As String
    rc.CursorLocation = adUseClient
    Str_Query = "SELECT DISTINCT fm.run_apo FROM apoderados a, fnza_mensualidad fm WHERE left(a.rut_apo," & Len(Text2.Text) & ")='" & Text2.Text & "' AND a.rut_apo=fm.run_apo ORDER BY a.rut_apo;"
    rc.Open Str_Query, conn
    List2.Clear
    While Not (rc.EOF)
        List2.AddItem rc("run_apo")
        rc.MoveNext
    Wend
    rc.Close
    List2.Visible = True
    List1.Visible = False
End Sub
Private Sub List2_DblClick()
    Text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    rc.CursorLocation = adUseClient
    rc.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Text2.Text & "' ORDER BY rut_apo;", conn
    rc.MoveFirst
    Flag_Sub = True
    Text1.Text = rc("nombre_apo")
    rc.Close
    Flag_Sub = False
End Sub
Private Sub List1_DblClick()
    Text1.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    rc.CursorLocation = adUseClient
    rc.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    rc.MoveFirst
    Flag_Sub = True
    Text2.Text = rc("rut_apo")
    rc.Close
    Flag_Sub = False
End Sub

