Results 1 to 11 of 11

Thread: Search For Record

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    Search For Record

    hello, i am a newbie in programming.

    i am creating a simple database program right now with a single table using ms access.

    i already finished some of its functions like add, save, delete, exit etc. my problem right now is i do not know how to search a particular record in my database and display its result to a table form in a datagrid. here is what i have so far...
    Code:
    Private Sub cmdSearch_Click()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\contact.mdb;Persist Security Info=False"
    
    Set rs = cn.Execute("SELECT * FROM Table1 WHERE contact Id = '" & txtContId.Text & "'")
    
    DataGrid1.DataSource = rs
    DataGrid1.Refresh
    
    End Sub
    What I would like to do is to a search a particular contact Id that is to be inputted in the txtContId.text and then show its other details in a table form using datagrid1.

    I hope somebody could help me with this....thank you in advance!

    God bless!

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

    Re: Search For Record

    Split into its own thread

    If you wish to contribute to the answer to someone else's question, then by all means, post in their thread.

    If, however, you have a question of your own, please create your own thread.

    Thanks.

  3. #3
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: Search For Record

    Ok, The problem was I was not populating the Id Text box before calling the SQL statement. The Program is running fine now with the statement

    Code:
    NavigateRecords()
    sqll = "SELECT * FROM branches WHERE Company_ID=  " & IDText.Text

  4. #4
    Lively Member Colin Dias's Avatar
    Join Date
    Jan 2008
    Posts
    99

    Re: Search For Record

    I will look into tagheuer34's question as soon as possible. I am planning to incorporate a search for my project as well.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    Re: Search For Record

    I will really wait for your suggestions regarding my problem in my code.

    Thank you in advance for any possible help that will be given.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Search For Record

    What problem would that be?

    So far you haven't told us what it is, so we can't really help you correct it.


    One obvious problem is that you have a field called "contact Id", which is a really bad idea - names with spaces in cause a lot of problems, so you should change it if possible (perhaps to "ContactId").

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Search For Record

    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    Re: Search For Record

    ok,

    my problem with the code I've given is that it is not giving any output. It results in an error "Data Member Not Found".

    That's why my question is what can anybody suggest to make my code produce result. And the result should be to output the other information of a partricular contact (name, address etc) by inputting it's contact Id in the contId textbox.

    thanx!

  9. #9
    Member
    Join Date
    Mar 2008
    Posts
    47

    Re: Search For Record

    Hi again Tagheuer34,

    Try to use Set keyword..Try this one,

    Set Datagrid1.datasource = rs

    Hope this helps

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    7

    Re: Search For Record

    hello krizaaa,

    thank you very much for your help. you're very kind.

    anyway, my problem was already solved. I used MSHFlexGrid instead of DataGrid to output my table to my form.

    thanks again....God bless!!!

  11. #11
    Member
    Join Date
    Mar 2008
    Posts
    47

    Re: Search For Record

    You're welcome..

    Anyways, I have tried your code and I also got "Data Member Not Found" error. Then I used Set datagrid1.datasource = rs. Learned that data source should be set. Then it works fine with the datagrid.

    You can try this in the future or for experimenting. Just sharing what I've learned..

    Thanks..

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