Search Coding

Blinky_Au

New member
Local time
Tomorrow, 06:55
Joined
Nov 22, 2007
Messages
1
Hey All,

First time poster!

Im having issues when it comes to creating code to do a couple of 'Search' related codes.

There are several things I need to do.

The first, is to have a search Text Box, which would be filled in with a word needed to be searched for eg 'John' now after clicking a 'Seach' Cmdbutton I need 3 Columns in a Table to be searched for 'John' and all the positive results I need the corresponding 'Name' which is also another Column to be shown below in a 'List' which can be highlighted.

I also need a similar code but this time instead of a Text Box, there is a List Box. And the selected item in the list to be searched for in only one Column in the same Table after a different Cmdbutton is pressed, and all the results to be shown in the same 'List' as above.

After either list has been created, I need another code for a CmdButton different to the other two, which will show the results of only ONE of the items which you select from the 'Search Result' list. It would show up in a new form and include several items from a Table.

I know im after a lot, but hopefully someone can help out!

Thanks,
Matty
 
The first, is to have a search Text Box, which would be filled in with a word needed to be searched for eg 'John' now after clicking a 'Seach' Cmdbutton I need 3 Columns in a Table to be searched for 'John' and all the positive results I need the corresponding 'Name' which is also another Column to be shown below in a 'List' which can be highlighted.
This is only one of your questions I am going to answer, because the rest of your questions can be answered by it too. So...

If I was going to search 3 fields from a table, just for a specific value, I would use the built-in query object to do this for me (using the criteria of the text box value, with "OR" to search each field), and then set my list object (listbox?) with a rowsource of that query. Sounds like you only want the list to display one column, a column that has values related to those records that return positive results? The rowsource would then only reflect one column from that query, accordingly.
I also need a similar code but this time instead of a Text Box, there is a List Box. And the selected item in the list to be searched for in only one Column in the same Table after a different Cmdbutton is pressed, and all the results to be shown in the same 'List' as above.
Just make another query with different criteria here. Same process as above, and call it when needed.

The only code you are going to need for this is the few lines you put with the Click event of the command buttons. DoCmd.OpenQuery...etc, etc... Of course, you will need to requery your list objects after you open them though, because the form from which you pressed the button will already be open.
 
Create a query contains the columns you need.

Type in forms[formname]!txtname at Criteria row in the column where you want the name to be searched.

Create a subform or listbox bound to this query.

add this in the click event of the search button:

listbox.recordsource = ""
listbox.recordsource = 'The query your just create'

You will see the subform or list box refresh after you click the search button.
 

Users who are viewing this thread

Back
Top Bottom