Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,538 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,757 people online right now. Registration is fast and FREE... Join Now!




Search a register with InputBoxes

 
Reply to this topicStart new topic

Search a register with InputBoxes

mosfesito70
13 Aug, 2008 - 01:39 PM
Post #1

New D.I.C Head
*

Joined: 10 Aug, 2008
Posts: 3


My Contributions
[font=Times New Roman][size=7] biggrin.gif Hola a todos. Tengo un proyecto en la cual deseo buscar un registro de una basa de datos usando la busqueda con un InputBox y que se llene dicho formulario con sus otros datos. Por el momento mi metodo de busqueda lo tengo en el mismo formulario, pero quisiera programarlo con un InputBox, Gracias
CODE

Option Explicit
Private Sub cmdBuscar_Click()
    Buscar
    ' Buscar el primer registro que coincida con el dato buscado
    
End Sub



Private Sub Form_Load()
    '
    Text2 = ""
    Option2.Value = True
    '
    Const sPathBase As String = "C:\Mis documentos\Proyecto\COLEGIO"
    '
    ' Crear la conexión manualmente
    ' Con "Provider=Microsoft.Jet.OLEDB.4.0;" se permite abrir bases de datos de Access 2000
    With Me.Adodc1
        .ConnectionString = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & sPathBase & ";"
            '& _
            "Persist Security Info=False"
        ' Indicarle de que tabla vamos a leer los datos
        .RecordSource = "CALIFICACIONES"
    End With
      
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    ' Se buscará sólo cuando pulsemos INTRO
    '
    ' Comprobar si la tecla pulsada es Intro: vbKeyReturn o 13 que es lo mismo
    If KeyAscii = vbKeyReturn Then
        On Error Resume Next
        ' Esta asignación evita que suene un BEEP
        KeyAscii = 0
        '
        Buscar
        cmdBuscar.Default = True
     End If
End Sub

Private Sub Buscar(Optional ByVal Siguiente As Boolean = False)
    ' Procedimiento para buscar el dato indicado                    (18/Ene/01)
    ' Si Siguiente = True, se busca a partir del registro activo
    Dim nReg As Long
    Dim vBookmark As Variant ' En ADO debe ser Variant, no vale un String
    Dim sADOBuscar As String
    '
    ' Iniciamos la detección de errores
    On Error Resume Next
    '
    ' Buscar la primera coincidencia en el recordset del Data1
    If Option1.Value Then
        ' Convertir el contenido de TextBox en un número
        nReg = Val(Text2)
        ' en el campo Au_ID
        sADOBuscar = "NO_CARNET = " & nReg
    End If
    If Option2.Value Then
        ' en el campo Author
        sADOBuscar = "NOM_AL Like '" & Text2.Text & "'"
    End If
    ' Guardar la posición anterior, por si no se halla lo buscado...
    vBookmark = Adodc1.Recordset.Bookmark
    '
    If Siguiente = False Then
        ' Buscar desde el principio
        Adodc1.Recordset.MoveFirst
        Adodc1.Recordset.Find sADOBuscar
    Else
        ' Busca a partir del registro actual
        Adodc1.Recordset.Find sADOBuscar, 1
    End If
    ' Devolverá un error si no se halla lo buscado
    ' aunque no siempre es así...
    If Err.Number Or Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then
        Err.Clear
        MsgBox "No existe el dato buscado o ya no hay más datos que mostrar."
        ' Posicionar el recordset en la posición guardada
        Adodc1.Recordset.Bookmark = vBookmark
    End If
End Sub
Private Sub cmdCancelRegistro_Click()
  Adodc1.Recordset.CancelUpdate
End Sub

Private Sub cmdExit_Click()
frmMenu.Show
frmRegistroCalificaciones.Hide
End Sub

Private Sub cmdNewRegistro_Click()
  Adodc1.Recordset.AddNew
End Sub

Private Sub cmdUpdateRegistro_Click()
  Adodc1.Recordset.Update
End Sub

User is offlineProfile CardPM
+Quote Post

thava
RE: Search A Register With InputBoxes
13 Aug, 2008 - 04:34 PM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 450



Thanked: 18 times
Dream Kudos: 50
My Contributions
English Pls sad3.gif
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Search A Register With InputBoxes
13 Aug, 2008 - 05:36 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Dream.In.Code has a policy where we require you to post your questions in English. Please re-post your question in English so we can understand what you're asking smile.gif
User is online!Profile CardPM
+Quote Post

cmount
RE: Search A Register With InputBoxes
15 Aug, 2008 - 10:35 AM
Post #4

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
I'll give a rough translation just off the top of my head as to what they're generally trying to say:

Hello everyone! I have a project in which the goal is to look for a register based on the data using search (something) for an InputBox & that will fill the form with the other data. For the moment my method of searching has the same form, but he wants to make it with an InputBox

Thanks

QUOTE(mosfesito70 @ 13 Aug, 2008 - 02:39 PM) *

[font=Times New Roman][size=7] biggrin.gif Hola a todos. Tengo un proyecto en la cual deseo buscar un registro de una basa de datos usando la busqueda con un InputBox y que se llene dicho formulario con sus otros datos. Por el momento mi metodo de busqueda lo tengo en el mismo formulario, pero quisiera programarlo con un InputBox, Gracias
CODE

Option Explicit
Private Sub cmdBuscar_Click()
    Buscar
    ' Buscar el primer registro que coincida con el dato buscado
    
End Sub



Private Sub Form_Load()
    '
    Text2 = ""
    Option2.Value = True
    '
    Const sPathBase As String = "C:\Mis documentos\Proyecto\COLEGIO"
    '
    ' Crear la conexión manualmente
    ' Con "Provider=Microsoft.Jet.OLEDB.4.0;" se permite abrir bases de datos de Access 2000
    With Me.Adodc1
        .ConnectionString = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & sPathBase & ";"
            '& _
            "Persist Security Info=False"
        ' Indicarle de que tabla vamos a leer los datos
        .RecordSource = "CALIFICACIONES"
    End With
      
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    ' Se buscará sólo cuando pulsemos INTRO
    '
    ' Comprobar si la tecla pulsada es Intro: vbKeyReturn o 13 que es lo mismo
    If KeyAscii = vbKeyReturn Then
        On Error Resume Next
        ' Esta asignación evita que suene un BEEP
        KeyAscii = 0
        '
        Buscar
        cmdBuscar.Default = True
     End If
End Sub

Private Sub Buscar(Optional ByVal Siguiente As Boolean = False)
    ' Procedimiento para buscar el dato indicado                    (18/Ene/01)
    ' Si Siguiente = True, se busca a partir del registro activo
    Dim nReg As Long
    Dim vBookmark As Variant ' En ADO debe ser Variant, no vale un String
    Dim sADOBuscar As String
    '
    ' Iniciamos la detección de errores
    On Error Resume Next
    '
    ' Buscar la primera coincidencia en el recordset del Data1
    If Option1.Value Then
        ' Convertir el contenido de TextBox en un número
        nReg = Val(Text2)
        ' en el campo Au_ID
        sADOBuscar = "NO_CARNET = " & nReg
    End If
    If Option2.Value Then
        ' en el campo Author
        sADOBuscar = "NOM_AL Like '" & Text2.Text & "'"
    End If
    ' Guardar la posición anterior, por si no se halla lo buscado...
    vBookmark = Adodc1.Recordset.Bookmark
    '
    If Siguiente = False Then
        ' Buscar desde el principio
        Adodc1.Recordset.MoveFirst
        Adodc1.Recordset.Find sADOBuscar
    Else
        ' Busca a partir del registro actual
        Adodc1.Recordset.Find sADOBuscar, 1
    End If
    ' Devolverá un error si no se halla lo buscado
    ' aunque no siempre es así...
    If Err.Number Or Adodc1.Recordset.BOF Or Adodc1.Recordset.EOF Then
        Err.Clear
        MsgBox "No existe el dato buscado o ya no hay más datos que mostrar."
        ' Posicionar el recordset en la posición guardada
        Adodc1.Recordset.Bookmark = vBookmark
    End If
End Sub
Private Sub cmdCancelRegistro_Click()
  Adodc1.Recordset.CancelUpdate
End Sub

Private Sub cmdExit_Click()
frmMenu.Show
frmRegistroCalificaciones.Hide
End Sub

Private Sub cmdNewRegistro_Click()
  Adodc1.Recordset.AddNew
End Sub

Private Sub cmdUpdateRegistro_Click()
  Adodc1.Recordset.Update
End Sub



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:28PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month