MS Access Forum / New Users / March 2006
Select name in one listbox and pull all matching names to second
|
|
Thread rating:  |
Ron Weaver - 11 Mar 2006 17:14 GMT I have a form with two listboxes. At this point I can select a name in listbox 1 and it just pulls that name (CustomerID) to the listbox 2. I need all matching names (Whether they are the same person or not), in listbox 2. List59: (listbox 1) SELECT [Order Date Query].CustomerID, [Order Date Query].StartDate, [Order Date Query].Expr1, [Order Date Query].CustPhone, [Order Date Query].OrderID FROM [Order Date Query]; List111: (listbox 2) SELECT [Customer Query].CustomerID, [Customer Query].Expr1 AS Expr2, [Customer Query].StartDate, [Customer Query].Phone, [Customer Query].OrderID FROM [Customer Query] WHERE ((([Customer Query].CustomerID)=[Forms]![OrderDateForm].[list59])); Thanks for everyones help.
Brian Bastl - 11 Mar 2006 18:07 GMT Ron,
Since you want the second listbox to show 'all' matching names, then you can't filter on CustomerID. You'll have to incorporate the Customer's name into the rowsource for List59, so you'll have to modify the SQL (below) for both listboxes to reflect the actual CustomerName and Customers Table.
There may be better ways to do it, but hopefully this will give a decent jumping off point.
Brian
.List59: (listbox 1) SELECT [tblCustomers].CustomerName, [Order Date Query].StartDate, [Order Date Query].Expr1, [Order Date Query].CustPhone, [Order Date Query].OrderID FROM [Order Date Query] INNER JOIN tblCustomers ON [Order Date Query].[CustomerID] = [tblCustomers].[CustomerID];
List111: (listbox 2) SELECT [Customer Query].CustomerID, [Customer Query].[CustomerName], [Customer Query].StartDate, [Customer Query].Phone, [Customer Query].OrderID FROM [Customer Query] WHERE ((([Customer Query].CustomerName) Like "*" & [Forms]![OrderDateForm].[list59] & "*"));
Ron Weaver - 11 Mar 2006 18:36 GMT Brian The customers name is in "Expr1" Please show me how the SQLs should read. Thanks
> Ron, > [quoted text clipped - 21 lines] > WHERE ((([Customer Query].CustomerName) Like "*" & > [Forms]![OrderDateForm].[list59] & "*")); Brian Bastl - 11 Mar 2006 18:47 GMT Ron,
I just reversed the rowsource order for List59 so that Expr1 (customer name) is the first column. Assuming that the Listbox does NOT have a control source, set the bound column to 1. You'll need to requery List111 in the After Update event of List59.
.List59: (listbox 1) SELECT [Order Date Query].Expr1, [Order Date Query].StartDate, [Order Date Query].CustomerID, [Order Date Query].CustPhone, [Order Date Query].OrderID FROM [Order Date Query];
List111: (listbox 2) SELECT [Customer Query].CustomerID, [Customer Query].[CustomerName], [Customer Query].StartDate, [Customer Query].Phone, [Customer Query].OrderID FROM [Customer Query] WHERE ((([Customer Query].CustomerName) Like "*" & [Forms]![OrderDateForm].[list59] & "*"));
Brian
> Brian > The customers name is in "Expr1" Please show me how the SQLs should read. [quoted text clipped - 25 lines] > > WHERE ((([Customer Query].CustomerName) Like "*" & > > [Forms]![OrderDateForm].[list59] & "*")); Ron Weaver - 11 Mar 2006 20:26 GMT Brian It doesn't work. I left listbox 1 alone because it had all the fields. On listbox 2, I changed CustomerName to Expr1 in two places. The listbox remains blank. Before I put this code in it was pulling a single name to listbox 2 based on CustomerID. I have checked for miss spelling, etc. The way this form works is: When the form is opened, the listboxes are blank. There are two text fields. One for StartDate and one for EndDate. After these are filled, I click on a control which refreshes the form and populates list 1. When I select a record in listbox 1, that populates listbox 2. Both listboxes are bound to one column. I hope this helps.
> Ron, > [quoted text clipped - 51 lines] > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > [Forms]![OrderDateForm].[list59] & "*")); Brian Bastl - 11 Mar 2006 20:56 GMT Ron,
Are you saying that your List59 is being filtered by date? I don't see a where clause in its rowsource.
Tell you what: if you want me to take a quick look at your db, you'll need to compact it, save a copy of it in A2000 file format or earlier, change the file extension from .mdb to .xxx, and zip it up. You can send it to me at:
bastelER<at>alltelER<dot>net 'remove capitalized letters and change punctuation appropriately
Otherwise, I can't help without knowing alot more about your form, its recordsource, the names of the pertinent tables and respective fieldnames pertaining to the listboxes, etc.
Brian
> Brian > It doesn't work. I left listbox 1 alone because it had all the fields. On [quoted text clipped - 63 lines] > > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > > [Forms]![OrderDateForm].[list59] & "*")); Ron Weaver - 11 Mar 2006 21:20 GMT Thanks Brian I may take you up on that. I just looked at the Customer Query. It is in the SQL statement along with formatting for the phone. I don't know why it's not in the row source in listbox 2. Should it be? Thanks for hanging in there with me.
> Ron, > [quoted text clipped - 93 lines] > > > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > > > [Forms]![OrderDateForm].[list59] & "*")); Ron Weaver - 11 Mar 2006 21:33 GMT Sorrty I got that backwards. I meant "Order Date Query" and "Listbox 1"
> Thanks Brian > I may take you up on that. I just looked at the Customer Query. It is in the [quoted text clipped - 99 lines] > > > > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > > > > [Forms]![OrderDateForm].[list59] & "*")); Brian Bastl - 12 Mar 2006 05:09 GMT Ron,
Like I said before, I have no idea what your db looks like. What is the purpose of the form on which the listboxes reside? Is the form bound or unbound? Are the listboxes bound or unbound? If the form is bound, what is its recordsource? What are the pertinent tables and fields relating to your listboxes? The SQL for the first listbox doesn't explain much, although I'm not sure why you need the telephone number in the first listbox, since it is being displayed in the second listbox.
Brian
> Sorrty > I got that backwards. I meant "Order Date Query" and "Listbox 1" [quoted text clipped - 102 lines] > > > > > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > > > > > [Forms]![OrderDateForm].[list59] & "*")); Ron Weaver - 12 Mar 2006 23:47 GMT Brian I have emailed you the database per your instructions. Let me know if for some reason you don't get it. Thanks for your help.
> Ron, > [quoted text clipped - 143 lines] > > > > > > > > WHERE ((([Customer Query].CustomerName) Like "*" & > > > > > > > > [Forms]![OrderDateForm].[list59] & "*")); Brian Bastl - 13 Mar 2006 03:32 GMT Ron,
nope, didn't get it.
I double-checked the address I gave you. It is correct.
bastel <at> alltel <dot> net
Brian
Ron Weaver - 13 Mar 2006 04:41 GMT I think my anti virus may have interfered. I will turn it off and try again.
> Ron, > [quoted text clipped - 9 lines] > > Brian Steve Schapel - 11 Mar 2006 18:15 GMT Ron,
Does [Order Date Query] include the customer's name? If not, can it be modified so that it does include the customer's name? And then for this field to be included in the Row Source of List59? How about [Customer Query], does that include the customer's name? If not, can it be modified so that it does include the customer's name? If you can set that up, then you will be able to modify the Where criteria for the query you use for List111, so that it points to the customer name instead of the CustomerID.
 Signature Steve Schapel, Microsoft Access MVP
> I have a form with two listboxes. At this point I can select a name in > listbox 1 and it just pulls that name (CustomerID) to the listbox 2. I need [quoted text clipped - 9 lines] > WHERE ((([Customer Query].CustomerID)=[Forms]![OrderDateForm].[list59])); > Thanks for everyones help. Ron Weaver - 11 Mar 2006 18:31 GMT Steve, the customer's name is in "Expr1". What do I do next?
> Ron, > [quoted text clipped - 20 lines] > > WHERE ((([Customer Query].CustomerID)=[Forms]![OrderDateForm].[list59])); > > Thanks for everyones help. Steve Schapel - 12 Mar 2006 05:39 GMT Ron,
Use this as the Row Source query for List111:
SELECT [Customer Query].CustomerID, [Customer Query].Expr1 AS Expr2, [Customer Query].StartDate, [Customer Query].Phone, [Customer Query].OrderID FROM [Customer Query] WHERE ((([Customer Query].Expr1)=[Forms]![OrderDateForm]![list59].[Column](2)));
 Signature Steve Schapel, Microsoft Access MVP
> Steve, the customer's name is in "Expr1". What do I do next? Ron Weaver - 12 Mar 2006 17:23 GMT Hi Steve I tried this , but I don't think you can use the column expression in a query. I got the error: Undefined Function'Forms!OrderDateForm!List59.column' in expression. It is strange, but when I use: WHERE ((([Customer Query].CustomerID)=[Forms]![OrderDateForm].[list59])), my form works perfectly, unfortunately it just returns the one record. I sure appreciate your thoughts.
> Ron, > [quoted text clipped - 8 lines] > > > Steve, the customer's name is in "Expr1". What do I do next? Steve Schapel - 13 Mar 2006 19:25 GMT Ron,
I think you might be right... it's been a while since I've done anything like this. I think what you need to do is put a hidden unbound textbox on the form, and set its Control Source to... =[list59].[Column](2) Let's say you name this textbox CustomerRef. Then write your query like... ... WHERE (([Customer Query].Expr1)=[Forms]![OrderDateForm]![CustomerRef])
 Signature Steve Schapel, Microsoft Access MVP
> Hi Steve > I tried this , but I don't think you can use the column expression in a [quoted text clipped - 4 lines] > perfectly, unfortunately it just returns the one record. I sure appreciate > your thoughts. Ron Weaver - 13 Mar 2006 20:42 GMT Steve I tried that. The selected name in Listbox 1 shows up in the textbox "CustomerRef", but not in ListBox 2. I still have the "After Update" property in listbox 1 as:'Me.List70.Requery' pointing to listbox 2. I need the name selected in listbox 1 to show all instances of that name in listbox 2. Thanks
> Ron, > [quoted text clipped - 13 lines] > > perfectly, unfortunately it just returns the one record. I sure appreciate > > your thoughts. Steve Schapel - 13 Mar 2006 22:42 GMT Ron,
What happened to List111? Is this now List70? What does it in fact show in Listbox 2/111/70? Is the Expr1 field in the [Customer Query] query the name of the customer, and matches the value of the customer name in [list59].[Column](2)?
 Signature Steve Schapel, Microsoft Access MVP
> Steve > I tried that. The selected name in Listbox 1 shows up in the textbox > "CustomerRef", but not in ListBox 2. I still have the "After Update" property > in listbox 1 as:'Me.List70.Requery' pointing to listbox 2. I need the name > selected in listbox 1 to show all instances of that name in listbox 2. > Thanks Ron Weaver - 13 Mar 2006 23:02 GMT I changed out the listbox 2, trying to fix the problem. It is now list70. Nothing else has changed. Expr1 is in both listboxes. Listbox 1 is still list59. If you would like the listbox SQLs I will be happy to send them.
> Ron, > [quoted text clipped - 9 lines] > > selected in listbox 1 to show all instances of that name in listbox 2. > > Thanks Steve Schapel - 13 Mar 2006 23:30 GMT Ron,
Ok, how about my other question: What does it in fact show in Listbox 2?
Ok, how about my other other question: Is the Expr1 field in the [Customer Query] query the name of the customer, and matches the value of the customer name in [list59].[Column](2)?
If you make a query like this... SELECT [Customer Query].CustomerID, [Customer Query].Expr1 AS Expr2, [Customer Query].StartDate, [Customer Query].Phone, [Customer Query].OrderID FROM [Customer Query] WHERE (([Customer Query].Expr1)=[Forms]![OrderDateForm]![CustomerRef]) ... and open the query in datasheet (when the form is open), does the query return the expected data?
 Signature Steve Schapel, Microsoft Access MVP
> I changed out the listbox 2, trying to fix the problem. It is now list70. > Nothing else has changed. Expr1 is in both listboxes. Listbox 1 is still > list59. If you would like the listbox SQLs I will be happy to send them. Ron Weaver - 15 Mar 2006 00:50 GMT Steve I just saw you response. I'm sorry I didn't see it earlier. I just figured this thing out and was in the process of going back in to let everyone know. This is what I did: First I created a new field "CustomerNumber" and added it to the Customer Table. I then assigned each customer a unique number. Then I had to update all effected queries and forms. Although I don't understand it, I had to position CustomerName first in listbox 2's guery. I changed The WHERE statement to 'WHERE ((([Customer Query].CustomerNumber)=[Forms]![OrderDateForm].[list59]));' in listbox 2. Now it works perfectly. When I select a customer with multiple orders, it pulls them all down to listbox 2. I want to thank you and everyone who has helped me with this.
Ron
> Ron, > [quoted text clipped - 16 lines] > > Nothing else has changed. Expr1 is in both listboxes. Listbox 1 is still > > list59. If you would like the listbox SQLs I will be happy to send them.
|
|
|