Results 1 to 14 of 14

Thread: Need code for searching a text box

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Need code for searching a text box

    I have created a simple database to store computer inventory data along w/the users they are assigned to. Access 2003. I need code to not only search the users last name, but also computer name, which include numbers and letters. Any help would be greatly appreciated. Also, I am real new to vb, so the simpler the better.
    thanks

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

    Re: Need code for searching a text box

    Welcome to the forums.

    I need to know a little bit about how your database is structured.

    You have separate fields for username and computername, right?

    What other fields do you have that might require searching on?

    How will the search begin? Will you be presenting the user with a VB form that has textboxes on it where they can enter in whatever it is they need to search for?

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

    Re: Need code for searching a text box

    Hi imagecko, welcome to VBForums!

    What code do you have at the moment?

    If you don't have any, I would recommend reading the "ADO tutorial" link in my signature, as most of the code you need is there. If you get stuck, post here and we can help

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Re: Need code for searching a text box

    I have created all my tables from scratch, I created a couple of forms and linked them to the tables. Below is a screen shot of the main form. I'd like to click on the search button, and have a box pop up that allows me to type into it the users last name (primarily) and pull up all records linked to that users name. Additional text boxes are first name, parole unit, last name. I am not sure of any specific database structure. Additionally, as suggested I will look at the tutorial.
    [IMG]D:\Data\OfficeStuff\Word\scrn1.doc[/IMG]

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

    Re: Need code for searching a text box

    Quote Originally Posted by imagecko
    I have created all my tables from scratch, I created a couple of forms and linked them to the tables. Below is a screen shot of the main form. I'd like to click on the search button, and have a box pop up that allows me to type into it the users last name (primarily) and pull up all records linked to that users name. Additional text boxes are first name, parole unit, last name. I am not sure of any specific database structure. Additionally, as suggested I will look at the tutorial.
    By database structure I mean the names of your tables and the names of the fields within the tables.

    Once you have all of the records for a specific user, what do you intend to do with them? How do you want them displayed on the screen?

    Are you using ADO?

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Re: Need code for searching a text box

    by the way...thanks for the warm welcome. My tables consist of the following:

    Computers
    CpuData
    Employees
    EmpTitle
    MonitorData
    ParoleUnits
    WinVer

    I am not sure how to determine whether I am using ADO or not. I did use the wizards to create command buttons that result in printing certain reports. I have not done any custom coding at all. I obviously did not attach the screen shot correctly, so let me read up on attaching files and re-submit.
    Thanks,
    Melissa

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

    Re: Need code for searching a text box

    Save the image to a image file like *.jpg or *.gif using MS Paint or other image software. Then upload that image with your post by clicking on the Manage Attachments button during a reply post. If you attach only one imagefile it will automatically display in your post.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Re: Need code for searching a text box

    Here is the screen shot
    Additionally,
    I've searched this site and the posts that I have seen has very difficult coding. Simply what I'd like to do, is the click on the binocular button. Have a msg box pop up that asks for you to input the item to search for. I'd like to search the following fields:
    CompName and
    UserLastName
    I would like the results to display in the same initial for displayed here.
    Thanks,
    Attached Images Attached Images  
    Last edited by imagecko; Nov 7th, 2005 at 04:02 PM.

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Re: Need code for searching a text box

    Am I doing something wrong? I just need some help with some simple code...I've searched and searched, and the ADO tutorial does not help me. I have already created my forms, my tables. it is all connected. I just need some simple code to search off a few boxes. Please help???

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

    Re: Need code for searching a text box

    A msgbox cannot take any kind of input, an InputBox (if available in Access) does, but it will only accept a single input. If you want to get more than one input you will need to create another form to get it.

    Once you have gotten input, you can create an SQL statement like this (where sCompName is the input for CompName, and sUserLastName is the input for UserLastName):
    VB Code:
    1. 'both must be exact matches:
    2. sSQL = "SELECT * FROM [i]tablename[/i] WHERE CompName = '" & sCompName & "' AND UserLastName ='" & sUserLastName & "'"
    3. 'both can be partial matches:
    4. sSQL = "SELECT * FROM [i]tablename[/i] WHERE CompName Like '*" & sCompName & *"' AND UserLastName ='*" & sUserLastName & "*'"
    In order to display this in your form, you will need to set the forms query to the sSQL mentioned above.

  11. #11
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Need code for searching a text box

    As your using Access, and you have linked the Form to a Table, you could adapt this:
    VB Code:
    1. [i]yourForm[/i].RecordSource = "SELECT * FROM [[i]yourTableName[/i]] WHERE [Field] = TextBox"

    Note: It is Syntax only... as an example. You will need to enclose the TextBox in parentisis.

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Need code for searching a text box

    That is an Access form, and this thread should be in the Office forum.
    You could write this in VB, and it would run on machines that don't have Office installed, but if you write it in VBA, then you need Office.

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

    Re: Need code for searching a text box

    this thread should be in the Office forum.
    Moved.

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Location
    Santa Maria, Ca. USA
    Posts
    6

    Re: Need code for searching a text box

    Sorry...I'll try what you guys are suggesting, then I will check the office forum. Thanks for your help. Maybe that is why I was having so much trouble.

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