#1 Consulta sencilla en VB
1,393
MENSAJES
#21 Re: Consulta sencilla en VB
Private Sub Opt1_Click(Index As Integer) CargarGrilla Index End Sub
65
MENSAJES
#22 Re: Consulta sencilla en VB
1,393
MENSAJES
#23 Re: Consulta sencilla en VB
Option Explicit
Dim i As Byte
'----------------------------------------------------------------------------------------
Private Function CargarGrilla(Index As Byte)
Dim StrSql As String
If txtOpcion = Empty Then
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from Personas"
Else
Select Case Index
Case 0
If IsNumeric(txtOpcion) Then
StrSql = "Select id, Nombre, Apellido, Telefono,Direccion, FechadeAlta from Personas where id=" & txtOpcion
Else
MsgBox "El codigo de cliente solo puede ser numérico", vbInformation, "sistemas"
txtOpcion = Empty
txtOpcion.SetFocus
Exit Function
End If
Case 1
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where Nombre like '" & txtOpcion & "%'"
Case 2
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where apellido like '" & txtOpcion & "%'"
Case 3
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where Telefono like '" & txtOpcion & "%'"
End Select
End If
rs.Open StrSql, cn, adOpenDynamic, adLockOptimistic
Dim grilla As MSFlexGrid '<----- Agregado
Set grilla = MSFlexGrid1 '<------ Agregado
grilla.Clear
grilla.Rows = 1
grilla.FormatString = "ID | Nombre |Apellido | Teléfono | Direccion "
Do While Not rs.EOF
grilla.AddItem rs!id & vbTab & rs!Nombre & vbTab & rs!Apellido & vbTab & rs!Telefono & vbTab & rs!Direccion
rs.MoveNext
Loop
rs.Close
End Function Private Sub txtOpcion_Change()
For i = 0 To 3
If Opt1(i).Value = True Then CargarGrilla Int(i)
Next i
End Sub 
65
MENSAJES
1,393
MENSAJES
#25 Re: Consulta sencilla en VB
]65
MENSAJES
#26 Re: Consulta sencilla en VB
Private Sub cmdBuscar_Click()
Criterio = txtOpcion.Text
Do While Not OptID Or OptNom Or OptApe Or OptTel = True
If OptID = False Then
If OptNom = False Then
If OptApe = False Then
If OptTel = False Then
MsgBox " no selecciono criterio"
End If
End If
End If
End If
Loop
If OptID = True Then
If Adodc.Recordset.EOF = True Then
Adodc.Recordset.MoveFirst
Else
Adodc.Recordset.Find "ID = '" & Criterio & "'", 1
End If
End If
If OptNom = True Then
If Adodc.Recordset.EOF = True Then
Adodc.Recordset.MoveFirst
Else
Adodc.Recordset.Find "Nombre = '" & Criterio & "'", 1
End If
End If
If OptApe = True Then
If Adodc.Recordset.EOF = True Then
Adodc.Recordset.MoveFirst
Else
Adodc.Recordset.Find "Apellido = '" & Criterio & "'", 1
End If
End If
If OptTel = True Then
If Adodc.Recordset.EOF = True Then
Adodc.Recordset.MoveFirst
Else
Adodc.Recordset.Find "Telefono = '" & Criterio & "'", 1
End If
End If
End Sub
1,393
MENSAJES
#27 Re: Consulta sencilla en VB

Do While Not OptID Or OptNom Or OptApe Or OptTel = True
If OptID = False Then
If OptNom = False Then
If OptApe = False Then
If OptTel = False Then
MsgBox " no selecciono criterio"
End If
End If
End If
End If
If txtOpcion = Empty Then
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from Personas"
Else
Select Case Index
Case 0
If IsNumeric(txtOpcion) Then
StrSql = "Select id, Nombre, Apellido, Telefono,Direccion, FechadeAlta from Personas where id=" & txtOpcion
Else
MsgBox "El codigo de cliente solo puede ser numérico", vbInformation, "sistemas"
txtOpcion = Empty
txtOpcion.SetFocus
Exit Function
End If
Case 1
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where Nombre like '" & txtOpcion & "%'"
Case 2
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where apellido like '" & txtOpcion & "%'"
Case 3
StrSql = "Select id, Nombre, Apellido, Telefono, Direccion, FechadeAlta from personas where Telefono like '" & txtOpcion & "%'"
End Select
End If 1,393
MENSAJES
#28 Re: Consulta sencilla en VB
65
MENSAJES
#29 Re: Consulta sencilla en VB
1,393
MENSAJES
#30 Re: Consulta sencilla en VB