Results 1 to 13 of 13

Thread: serch database

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    serch database

    Ok, I have a Database in my app folder in a folder called database
    the data base is called dtc and in it I have a table called Dtc
    the table has 2 columns, DTC and Description
    The DTC column is filled with Dtc numbers like P0001 P0002 etc and the description gives a description of each Dtc

    On my frmDtcSearch form I have a listview called lvDtcSearch
    A command button called cmdDtcSearch
    A textbox called txtDtcSearch
    and ADODC1

    I am trying to make it so when I type in lets say P0301, and click button it will search database, then add the search (P0301) and Description from database to the listview.

    Can someone get me started with this?
    Thanx

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    I'm not real familiar with using bound data controls, but I think there is a Find method associated with it.

    Try
    Code:
    Adodc1.Recordset.Find "P0301"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: serch database

    I have tried that but
    "P0301" Variable not defined

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    P0301 should not be a variable, it should be the thing that you are looking for.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: serch database

    Ok this is what I came up with
    Code:
    Private Sub cmdDtcSearch_Click()
    
    
    Dim search As String
    Dim Clientname As String
    search = txtDtcSearch.Text
    Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = "SELECT * from Dtc WHERE dtc LIKE '%" & search & "%'"
    Adodc1.Refresh
            Dim lCt As Long
    
    
            lCt = hyperDtcSearch.Count
    
    If Adodc1.Recordset.EOF Then
    If txtDtcSearch.Text = "P0001" Then
    
    txtDtcSearch.Text = ""
    MsgBox "Input Valid Dtc (P****) in text box"
    Else
    hyperDtcSearch.ItemAdd lCt, "", txtDtcSearch.Text, 6, 3
    hyperDtcSearch.SubItemsAdd lCt, 1, "No Matching DTCs Found"
    End If
    Else
    Adodc1.Recordset.MoveFirst
    End If
    
    
    Do Until Adodc1.Recordset.EOF
    
    
    hyperDtcSearch.ItemAdd lCt, "", Adodc1.Recordset.Fields(0), 6, 3
    hyperDtcSearch.SubItemsAdd lCt, 1, Adodc1.Recordset.Fields(1)
    
    
    
    
    Adodc1.Recordset.MoveNext
    Loop
    If Adodc1.Recordset.EOF And Adodc1.Recordset.RecordCount > 1 Then
    MsgBox "Records Found"
    End If
    End Sub
    The only issue I am having is with this line
    txtDtcSearch.Text = ""

    How do I tell if the text box is empty?

    thanx

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    Code:
    'two ways
    
    If txtDtcSearch.Text = vbNullString Then
       Msgbox "Nothing to search for"
    End If
    'or check the reverse
    
    If txtDtcSearch.Text <> vbNullString Then
       'place search code here
    Else
       Msgbox "Nothing to search for"
    End If

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: serch database

    Code:
    If txtDtcSearch.Text = vbNullString Then
    thank you very much,
    Now how would I check if the textbox has 5 characters in it
    (P0000 etc)

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: serch database

    vb Code:
    1. If Len(Trim(txtDtcSearch.Text)) = 5 Then
    2.     MsgBox "txtDtcSearch is having 5 characters in it"
    3. End If
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    Quote Originally Posted by ganeshmoorthy
    vb Code:
    1. If Len(Trim(txtDtcSearch.Text)) = 5 Then
    2.     MsgBox "txtDtcSearch is having 5 characters in it"
    3. End If
    And I would put this in the Change event so that it would fire each time a change was made.

  10. #10
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: serch database

    Quote Originally Posted by Hack
    And I would put this in the Change event so that it would fire each time a change was made.

    How about Validate event?
    IIF(Post.Rate > 0 , , )

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    Change will fire instantly. Validate will fire when it loses focus.

  12. #12
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: serch database

    Oh yeah, thats right, I thought OP wanted to validate if there is 5 characters. My mistake. Sorry
    IIF(Post.Rate > 0 , , )

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: serch database

    Quote Originally Posted by zeezee
    Oh yeah, thats right, I thought OP wanted to validate if there is 5 characters. My mistake. Sorry
    No reason to be sorry. He does want to validate that. It is just a matter of the best place to put the validation code. You could use the validate event, and it would work. I just think that knowing instantly would be preferable to knowing after the fact.

    However, in some cases, because of application requirements, my approach doesn't work, and yours would.

    We are all about options. Let the OP decide which way he wants to go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width