Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

codigo para buscar un registro

Estas en el tema de codigo para buscar un registro en el foro de Visual Basic clásico en Foros del Web. Soy nuevo en esto de Vb, estoy haciendo un sistema en vb 6.0, utilizo sql server, hago el enlace mediante un adodc1, como le puedo ...
  #1 (permalink)  
Antiguo 15/05/2005, 18:54
 
Fecha de Ingreso: mayo-2005
Mensajes: 3
Antigüedad: 19 años
Puntos: 0
De acuerdo codigo para buscar un registro

Soy nuevo en esto de Vb, estoy haciendo un sistema en vb 6.0, utilizo sql server, hago el enlace mediante un adodc1, como le puedo hacer para que en un inputbox ingrese el numero de idetificacion de algun cliente y una vez que lo encuentre me envie todos sus datos a sus respectivos textbox, si alguien tiene el codigo para eso, se lo agradecere mucho, ya pase buen rato tratando de hacer esto y no sale
  #2 (permalink)  
Antiguo 16/05/2005, 08:30
 
Fecha de Ingreso: diciembre-2004
Mensajes: 79
Antigüedad: 19 años, 4 meses
Puntos: 0
respuesta

hola no te puedo explicar el codigo completo pero aqui tienes un ejemplo trabajo con ado preo to creo las conexiones es decir no utilizo el control adodc1 si no que hago lo siguiente

dim conexion as adodb.conexion
dim rs as adodb.recordset etc.

bueno aqui te paso el codigo

Private Sub Command3_Click()
Dim rsgeneral As ADODB.Recordset
dim numerocontrol as string
numcontrol = InputBox("Introduce el numero de control")
If numcontrol = "" Then
Exit Sub
Else
conexion'aqui es donde llamo mo conexion me imagino que solo tienes que modificar esto y poner tucontrol adodc1
Set rsnumero = New ADODB.Recordset
rsnumero.Open "SELECT *FROM registrardatos", con, adOpenDynamic, adLockReadOnly
rsnumero.Filter = "[numcontrol]='" & numcontrol & "'"
Set rsgeneral = rsnumero

If rsnumero.EOF Then
MsgBox "El Numero" & vbCrLf & "[ " & numcontrol & " ]" & vbCrLf & " no fue localizado.", vbCritical
Exit Sub
Else
Text1 = IIf(IsNull(rsgeneral("nombres")), "Campo sin Registro", Trim(rsgeneral("nombres")))
Text2 = IIf(IsNull(rsgeneral("carrera")), "Campo sin Registro", Trim(rsgeneral("carrera")))
Text3 = IIf(IsNull(rsgeneral("escuela")), "Campo sin Registro", Trim(rsgeneral("escuela")))
Text4 = IIf(IsNull(rsgeneral("direscuela")), "Campo sin Registro", Trim(rsgeneral("direscuela")))
Text5 = IIf(IsNull(rsgeneral("director")), "Campo sin Registro", Trim(rsgeneral("director")))
Text6 = IIf(IsNull(rsgeneral("objetoservicio")), "Campo sin Registro", Trim(rsgeneral("objetoservicio")))
Text7 = IIf(IsNull(rsgeneral("actividades")), "Campo sin Registro", Trim(rsgeneral("actividades")))
Text8 = IIf(IsNull(rsgeneral("dependencia")), "Campo sin Registro", Trim(rsgeneral("dependencia")))
Text9 = IIf(IsNull(rsgeneral("dirdepen")), "Campo sin Registro", Trim(rsgeneral("dirdepen")))
Text10 = IIf(IsNull(rsgeneral("unidadad")), "Campo sin Registro", Trim(rsgeneral("unidadad")))
Text11 = IIf(IsNull(rsgeneral("responsable")), "Campo sin Registro", Trim(rsgeneral("responsable")))
Text12 = IIf(IsNull(rsgeneral("cargoresponsable")), "Campo sin Registro", Trim(rsgeneral("cargoresponsable")))
Text13 = IIf(IsNull(rsgeneral("diasprestacion")), "Campo sin Registro", Trim(rsgeneral("diasprestacion")))
Text14 = IIf(IsNull(rsgeneral("finicio")), "Campo sin Registro", Trim(rsgeneral("finicio")))
Text15 = IIf(IsNull(rsgeneral("ftermino")), "Campo sin Registro", Trim(rsgeneral("ftermino")))
Text16 = IIf(IsNull(rsgeneral("fregistro")), "Campo sin Registro", Trim(rsgeneral("fregistro")))
Text17 = IIf(IsNull(rsgeneral("horario")), "Campo sin Registro", Trim(rsgeneral("horario")))
Text18 = IIf(IsNull(rsgeneral("programa")), "Campo sin Registro", Trim(rsgeneral("programa")))
Text19 = IIf(IsNull(rsgeneral("semestre")), "Campo sin Registro", Trim(rsgeneral("semestre")))
Text20 = IIf(IsNull(rsgeneral("horas")), "Campo sin Registro", Trim(rsgeneral("horas")))
Text21 = IIf(IsNull(rsgeneral("numcontrol")), "Campo sin Registro", Trim(rsgeneral("numcontrol")))
End If
Exit Sub
End If
End Sub
  #3 (permalink)  
Antiguo 16/05/2005, 08:34
 
Fecha de Ingreso: diciembre-2004
Mensajes: 79
Antigüedad: 19 años, 4 meses
Puntos: 0
ya que si lo que te mando no te funciona esto esta comprobado

siempre y cuando tu conexion este bien hecha aqui te va el codigo claro no como lo quiere modifica

Dim existe As String
Dim nombre As String
nombre = inoutbox(nombre)
If nombre = "" Then
Exit Sub
Else

Adodc1.RecordSource = "SELECT *FROM busqueda WHERE nombres = '" & nombre & "'"
Adodc1.Refresh

With Adodc1.Recordset
'si no encuentra
If .RecordCount = 0 Then
txtcarrera.SetFocus
Exit Sub
Else
'si encuentra registro
'Text1 = !nombres
existe = MsgBox("Ya Existe un alumno con ese nombre" & vbCrLf _
& " Desea Consultar sus datos", vbInformation + vbYesNo)
If existe = vbYes Then
txtnombre = !nombre
txtpaterno = !paterno
txtmaterno = !materno
txtcarrera = !carrera
Cmbescuela = !escuela
'txtescuela = !escuela
txtdirescuela = !direscuela
txtdirector = !director
txtobjetivo = !objetoservicio
txtactividades = !actividades
txtdependencia = !dependencia
txtdirdependencia = !dirdepen
txtunidad = IIf(!unidadad = "", "No Registrado", !unidadad)
txtresponsable = !responsable
txtcargo = !cargoresponsable ' = IIf(txtcargo = "", "No Proporcionado por el usuario", txtcargo)
txtdias = !diasprestacion ' = IIf(txtdias = "", "No Proporcionado por el usuario", txtdias)
Finicio = !Finicio
'txtinicio = !Finicio ' = IIf(Finicio = "", "No Proporcionado por el usuario", Finicio)
Ftermino = !Ftermino ' = IIf(Ftermino = "", "No Proporcionado por el usuario", Ftermino)
Fentrega = !Fentrega ' = IIf(Fentrega = "", "No Proporcionado por el usuario", Fentrega)
'!Ftermino = IIf(Ftermino = "", "No Proporcionado por el usuario", Ftermino)
'txtregistro = !Fregistro '= IIf(Label9.Caption = "", "No Proporcionado por el usuario", Label9.Caption)
txthorario = !horario
Cmbprograma = !programa ' = IIf(Cmbprograma = "", "No Proporcionado por el usuario", Cmbprograma)
Cmbsemestre = !semestre '= IIf(Cmbsemestre = "", "No Proporcionado por el usuario", Cmbsemestre)
Cmbhoras = !horas '= IIf(Cmbhoras = "", "No Proporcionado por el usuario", Cmbhoras)
txtnumero = !numcontrol ' = IIf(txtnumero = "", "No Proporcionado por el usuario", txtnumero)
numeroeliminar = Trim(txtnumero)
Label30.Caption = !numero
Option1.Enabled = False
Option2.Enabled = False
Tool.Buttons(1).Enabled = False
Exit Sub
Else
'MsgBox "Presiono NO"
Exit Sub
End If
Exit Sub
End If
End With
End If


'espero por lo menos me digas si te funciono
  #4 (permalink)  
Antiguo 16/05/2005, 08:50
Avatar de Developer9
(Desactivado)
 
Fecha de Ingreso: abril-2005
Ubicación: Mi Ecuador del alma
Mensajes: 4.196
Antigüedad: 19 años
Puntos: 47
Si necesitas un ejemplo de consulta a base yo tengo muchos, pero utilizando ADO, y creando un dsn que apunte a tu base en SQL Server
  #5 (permalink)  
Antiguo 28/05/2005, 16:48
 
Fecha de Ingreso: mayo-2005
Mensajes: 3
Antigüedad: 19 años
Puntos: 0
Cita:
Iniciado por xochitemol
siempre y cuando tu conexion este bien hecha aqui te va el codigo claro no como lo quiere modifica

Dim existe As String
Dim nombre As String
nombre = inoutbox(nombre)
If nombre = "" Then
Exit Sub
Else

Adodc1.RecordSource = "SELECT *FROM busqueda WHERE nombres = '" & nombre & "'"
Adodc1.Refresh

With Adodc1.Recordset
'si no encuentra
If .RecordCount = 0 Then
txtcarrera.SetFocus
Exit Sub
Else
'si encuentra registro
'Text1 = !nombres
existe = MsgBox("Ya Existe un alumno con ese nombre" & vbCrLf _
& " Desea Consultar sus datos", vbInformation + vbYesNo)
If existe = vbYes Then
txtnombre = !nombre
txtpaterno = !paterno
txtmaterno = !materno
txtcarrera = !carrera
Cmbescuela = !escuela
'txtescuela = !escuela
txtdirescuela = !direscuela
txtdirector = !director
txtobjetivo = !objetoservicio
txtactividades = !actividades
txtdependencia = !dependencia
txtdirdependencia = !dirdepen
txtunidad = IIf(!unidadad = "", "No Registrado", !unidadad)
txtresponsable = !responsable
txtcargo = !cargoresponsable ' = IIf(txtcargo = "", "No Proporcionado por el usuario", txtcargo)
txtdias = !diasprestacion ' = IIf(txtdias = "", "No Proporcionado por el usuario", txtdias)
Finicio = !Finicio
'txtinicio = !Finicio ' = IIf(Finicio = "", "No Proporcionado por el usuario", Finicio)
Ftermino = !Ftermino ' = IIf(Ftermino = "", "No Proporcionado por el usuario", Ftermino)
Fentrega = !Fentrega ' = IIf(Fentrega = "", "No Proporcionado por el usuario", Fentrega)
'!Ftermino = IIf(Ftermino = "", "No Proporcionado por el usuario", Ftermino)
'txtregistro = !Fregistro '= IIf(Label9.Caption = "", "No Proporcionado por el usuario", Label9.Caption)
txthorario = !horario
Cmbprograma = !programa ' = IIf(Cmbprograma = "", "No Proporcionado por el usuario", Cmbprograma)
Cmbsemestre = !semestre '= IIf(Cmbsemestre = "", "No Proporcionado por el usuario", Cmbsemestre)
Cmbhoras = !horas '= IIf(Cmbhoras = "", "No Proporcionado por el usuario", Cmbhoras)
txtnumero = !numcontrol ' = IIf(txtnumero = "", "No Proporcionado por el usuario", txtnumero)
numeroeliminar = Trim(txtnumero)
Label30.Caption = !numero
Option1.Enabled = False
Option2.Enabled = False
Tool.Buttons(1).Enabled = False
Exit Sub
Else
'MsgBox "Presiono NO"
Exit Sub
End If
Exit Sub
End If
End With
End If


'espero por lo menos me digas si te funciono
me marca error en el objeto adodc1 y el metodo refresh, ademas cuando introduzco un registro invalido tambien me dice que existe y si quiero ver sus datos, otra es cuando introduzco un registro valido al darle la opcion de ver sus datos no los manda a sus respectivos textbox
  #6 (permalink)  
Antiguo 28/05/2005, 16:50
 
Fecha de Ingreso: abril-2005
Mensajes: 3.083
Antigüedad: 19 años
Puntos: 17
Dios mío... Vaya dolor de ojos (por los trozos de código en sí, por su sintaxis y por lo "masivos" que son)...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:52.