control source and listbox values

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
201
Office Version
  1. 365
My listbox created from a query works without me defining a "control source". Do I need to define a control source? Secondly, when a user makes a selection from my listbox, I want the selection to refer to a different field (tied to that record) and that field will be the "criteria" for additional queries. How do I tell populate the "criteria" via a selection from a listbox and its associated field?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How do you want to use the selected items in the criteria of the query?

Do you want them in an IN clause?

Something like this perhaps:
HTML:
SELECT *
 
FROM PortfolioPerf
 
WHERE FundName IN (< list of fund names here >)
This would return all records for the fund names in the list.

The list would need to be construct from the listbox.
 
Upvote 0
Well, I had it coded as "none" and I had it coded as "simple". Neither seems to work as far as recognizing my selection. When I temporarily switched my list box to list only the fund name, the query and criteria still didn't work. So, it must be that the form is not recognizing a "selection".
 
Upvote 0
Here is my code in the query. Perhaps I should replace "HAVING" with "WHERE". I want the query to sum the record values for all records with the specified fund name. Before, when I just typed in "Galliard Dow Corning" for the criteria, the query worked. But now, I have a reference to my form and the listbox in the form, and it returns nothing. Here is my SQL:

SELECT COMPLIANCE_DATA.DATE, COMPLIANCE_DATA.[Fund Name], COMPLIANCE_DATA.[Compliance Sector 1], Sum(COMPLIANCE_DATA.[BE MKT]) AS [SumOfBE MKT1]
FROM COMPLIANCE_DATA
GROUP BY COMPLIANCE_DATA.DATE, COMPLIANCE_DATA.[Fund Name], COMPLIANCE_DATA.[Compliance Sector 1]
HAVING (((COMPLIANCE_DATA.[Fund Name])=[Forms]![Compliance Reports]![Galliard Portfolios]));
 
Upvote 0
Aha! I am able to make it work! Norie your orginal instructions worked, I just had to make a couple of adjustments. First, I needed to eliminate the multiselect aspect. Second, I needed to switch around the columns making the field in the list box that was visible was column 2, but the field/column that the criteria kept looking at was field/column 1.

So, in this case, it won't work on multiselect listboxes. .

Thank you so much!!!!
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top