View Full Version : Sorting and Searching


Oldsoftboss
07-01-2006, 03:49 PM
This example demonstrates a way to sort listbox columns in ascending and decending order, and how to programmatically narrow a search in any field of the list box.

Dave

kentwood
07-05-2006, 09:04 AM
This is very neat. Thanks for posting. I can see many uses for this.

ddrew
07-31-2006, 07:56 AM
OldSoftBoss, ive been using your example posted hear and adapted it to suit my DB, is there a way that I can ajust the coloum widths in the list box. Ideally they need to be dynamic, i.e to auto adjust as information was displayed. Thanks!

Oldsoftboss
08-01-2006, 04:15 AM
Dynamically, not that I know of. But you can manage the listbox when dragging the edge of the form

ddrew
08-02-2006, 05:47 AM
Just to let you know that Ive been impementing parts of this into my own DB, personaaly I think its so much better than a subform. The sort function is excellent. Im still woring on the resizing function. Two questions though;

1. Can I create a report from the results? As I had it before with one query it wasnt a problem, now when I sort its using different queries.

2. How can I show how many records have been found in the search?

Thanks!

Oldsoftboss
08-03-2006, 12:32 AM
Yes to both accounts.

Base the report on the same record source as the listbox.

You can do a record count. Create a text box on your Form/Report, and as the control source put =Count(*)

Dave

ddrew
08-03-2006, 03:26 AM
OK I understand the count function, but with the report I have one button to open a report, but because the list can be based on a number of different querries it dosent know which one to look at. i.e I can click on the lbls and reorder decending or ascending , so the list is now looking at a different query. How can I tell it which one?

Oldsoftboss
08-04-2006, 01:49 AM
Maybe declare a variable at the top of the forms code

Dim strQuery as String

then when a label is clicked, you can load the query to the variable.
strQuery = "yourQueryName"

Once you know this you may be able to do a dcount on the query.

Dave

mOs
08-22-2006, 01:00 PM
Quick Question on this guys..I more than appreciate what you've done OSB however, I need a simple Search Form and I was wondering what files would I need to delete and which query would I edit to implement and alter this to my fashion...I have already stretched the Search box and moved it to my liking...I just need to remove the other files that aren't needed for a simple project..

Thanks in advance

Might I add that Im NOVICE with Access 2003..lol

mOs
08-22-2006, 01:02 PM
Quick Question on this guys..I more than appreciate what you've done OSB however, I need a simple Search Form and I was wondering what files would I need to delete and which query would I edit to implement and alter this to my fashion...I have already stretched the Search box and moved it to my liking...I just need to remove the other files that aren't needed for a simple project..

Thanks in advance

Might I add that Im NOVICE with Access 2003..lol

wardster
08-24-2006, 01:27 AM
Hi - the query you need to edit is: "qryCDNoAsc" that is the one used to populate the list box when the form first loads, the others are only used when you click on the labels to re-order the list.

Hi Have attached a cut down version you could have a look at - and also incorporated a few other ideas i have picked up from this site.

Ian

wardster
08-24-2006, 01:34 AM
sorry just spotted a mistake in the previous attachment - rectified in this one, time did not update on change.

Bee
08-24-2006, 03:31 PM
sorry just spotted a mistake in the previous attachment - rectified in this one, time did not update on change.
Hi Wardster,

I have tried to modify your example; however, I can't get the search function to work in my version. Does it only depend on the txtSearch_Change() procedure or is there any other code that I have missed.

Thanks in advance.
B

wardster
08-25-2006, 12:54 AM
Hi B,

You need the code as mentioned above > txtSearch_Change()

in order for it to work correctly you need to have both or the text boxes [txtSearch] and [txtSearch2] on your form and named the same.

2nd Point to ensure is that in your query, your form is referenced by its name - i have called mine frmMain so the code is Like "*" & [Forms]![frmMain]![txtSearch2] & "*"
If you have named your form differently you will need to modify the form name.

This then checks the form for [txtSearch2] and filters according to its value.

Regards - Ian

Bee
08-25-2006, 03:38 AM
Hi B,

You need the code as mentioned above > txtSearch_Change()

in order for it to work correctly you need to have both or the text boxes [txtSearch] and [txtSearch2] on your form and named the same.

2nd Point to ensure is that in your query, your form is referenced by its name - i have called mine frmMain so the code is Like "*" & [Forms]![frmMain]![txtSearch2] & "*"
If you have named your form differently you will need to modify the form name.

This then checks the form for [txtSearch2] and filters according to its value.

Regards - Ian
It's working perfectly now, thank you very much Ian.

B

Bee
08-26-2006, 07:33 AM
I wanted to view different forms using the same list box. For example the user can select from a combo box what form they wanted to open. I am not sure how to do the 'Raw source type' bit.

I created a query for each form i want to run and then wrote an if Statment that runs a query depending on user's selection. How do you get Row souce type written in VB?

Thank you,
B

kerie
09-09-2006, 05:47 AM
thank you Oldsoftboss, this has been a real help, its just the kind of search i been trying to do ............................. but, and there had to be one lol, i cant get my links to work from within the search, is there anything you could suggest please?

many thanks

kerie
09-09-2006, 05:54 AM
thank you Oldsoftboss, this search is great, i been trying to get something like this to work for a while now, but ....................... and there always has to be one, there is one problem, the search is working perfect, however, i cannot use my links when they are in the search result box, is there a way around this please,

thanks

rhett7660
09-22-2006, 10:11 AM
Wardstar..

Do you have a version that doesn't have all the other stuff opening.... Just the forms/qry/tbl??

Thanks
R~

Grum
10-10-2006, 07:30 AM
Well done Oldsoftboss, this is a great little tool. One question, how have you been able to change the colour of the text box txtSearch when it has the focus? I can't find any code for it! I'd like to give it a different colour - this would have numerous other uses!!

Thanks again for the tool!

Oldsoftboss
10-19-2006, 03:45 AM
Conditional Formatting.
In Design View, select the textbox, then go Tools -> Conditional Formatting, then select Got Focus

Dave