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
Re: Need code for searching a text box
Welcome to the forums. :wave:
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?
Re: Need code for searching a text box
Hi imagecko, welcome to VBForums! :wave:
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 :)
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]
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.
http://www.vbforums.com/
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?
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
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.
1 Attachment(s)
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,
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???
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:
'both must be exact matches:
sSQL = "SELECT * FROM [i]tablename[/i] WHERE CompName = '" & sCompName & "' AND UserLastName ='" & sUserLastName & "'"
'both can be partial matches:
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.
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:
[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.
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.
Re: Need code for searching a text box
Quote:
this thread should be in the Office forum.
Moved.
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.