All - new to the forum, and today marks my first post.
I have a combo box that populates many listboxes based on a selection (listbox values are coming from another table [Master]) - simple enough. I want the listboxes to populate with DISTINCT entries - also seems simple enough (right?).
As you'll see below, if the user selects "All" from the combo box (cboSite), I want the listboxes to populate with distinct values from all sites; otherwise, any other selection is a unique site and the listboxes will populate with distinct values based on that unique site.
This works BEAUTIFULLY if I select a unique site, but when I select "All", there is always one (and only one) duplicate value in EACH listbox. That is to say: all values but one in the listbox are distinct.
FOR EXAMPLE:
I'm totally stumped! Any ideas as to why this might be happening?
As usual, forgive me if I'm accidentally omitting details/am using incorrect formatting for my question (still trying to figure out the ropes!). Been using Access/VBA just about every day for the past 3 months.
EDIT: using Access 2010
I have a combo box that populates many listboxes based on a selection (listbox values are coming from another table [Master]) - simple enough. I want the listboxes to populate with DISTINCT entries - also seems simple enough (right?).
As you'll see below, if the user selects "All" from the combo box (cboSite), I want the listboxes to populate with distinct values from all sites; otherwise, any other selection is a unique site and the listboxes will populate with distinct values based on that unique site.
This works BEAUTIFULLY if I select a unique site, but when I select "All", there is always one (and only one) duplicate value in EACH listbox. That is to say: all values but one in the listbox are distinct.
FOR EXAMPLE:
- Select unique site (not "All") from "cboSite"
- The listbox "lstMajEquip" (which only has values "Yes" and "No") populates to show "Yes" and "No"
- Select "All" from "cboSite"
- The listbox "lstMajEquip" (which only has values "Yes" and "No") populates to show "Yes","No", and "No" (what?!)
I'm totally stumped! Any ideas as to why this might be happening?
As usual, forgive me if I'm accidentally omitting details/am using incorrect formatting for my question (still trying to figure out the ropes!). Been using Access/VBA just about every day for the past 3 months.
EDIT: using Access 2010
Code:
Private Sub cboSite_Change()
If Me.cboSite = "All" Then
Me.lstBusiness.RowSource = "SELECT DISTINCT Master.Business, Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.Business) IS NOT NULL) And ((Master.Business)<>''));"
Me.lstProjectSpeed.RowSource = "SELECT DISTINCT Master.[Project Speed], Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.[Project Speed]) IS NOT NULL) And ((Master.[Project Speed])<>''));"
Me.lstExecutionType.RowSource = "SELECT DISTINCT Master.[Execution Type], Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.[Execution Type]) IS NOT NULL) And ((Master.[Execution Type])<>''));"
Me.lstEngineeringBy.RowSource = "SELECT DISTINCT Master.[Engineering By], Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.[Engineering By]) IS NOT NULL) And ((Master.[Engineering By])<>''));"
Me.lstConstructionBy.RowSource = "SELECT DISTINCT Master.[Construction By], Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.[Construction By]) IS NOT NULL) And ((Master.[Construction By])<>''));"
Me.lstComplvsReturn.RowSource = "SELECT DISTINCT Master.Compl_vs_Return, Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.Compl_vs_Return) IS NOT NULL) And ((Master.Compl_vs_Return)<>''));"
Me.lstProjectType.RowSource = "SELECT DISTINCT Master.Project_Type, Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False) And ((Master.Project_Type) IS NOT NULL) And ((Master.Project_Type)<>''));"
Me.lstMajEquip.RowSource = "SELECT DISTINCT Master.MajorEquipment, Master.Site, Master.Exclude FROM Master WHERE (((Master.Exclude)=False));"
Else
Me.lstBusiness.RowSource = "SELECT DISTINCT Master.Business, Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.Business) IS NOT NULL) And ((Master.Business)<>'') And ((Master.Exclude)=False));"
Me.lstProjectSpeed.RowSource = "SELECT DISTINCT Master.[Project Speed], Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.[Project Speed]) IS NOT NULL) And ((Master.[Project Speed])<>'') And ((Master.Exclude)=False));"
Me.lstExecutionType.RowSource = "SELECT DISTINCT Master.[Execution Type], Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.[Execution Type]) IS NOT NULL) And ((Master.[Execution Type])<>'') And ((Master.Exclude)=False));"
Me.lstEngineeringBy.RowSource = "SELECT DISTINCT Master.[Engineering By], Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.[Engineering By]) IS NOT NULL) And ((Master.[Engineering By])<>'') And ((Master.Exclude)=False));"
Me.lstConstructionBy.RowSource = "SELECT DISTINCT Master.[Construction By], Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.[Construction By]) IS NOT NULL) And ((Master.[Construction By])<>'') And ((Master.Exclude)=False));"
Me.lstComplvsReturn.RowSource = "SELECT DISTINCT Master.Compl_vs_Return, Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.Compl_vs_Return) IS NOT NULL) And ((Master.Compl_vs_Return)<>'') And ((Master.Exclude)=False));"
Me.lstProjectType.RowSource = "SELECT DISTINCT Master.Project_Type, Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.Project_Type) IS NOT NULL) And ((Master.Project_Type)<>'') And ((Master.Exclude)=False));"
Me.lstMajEquip.RowSource = "SELECT DISTINCT Master.MajorEquipment, Master.Site, Master.Exclude FROM Master WHERE (((Master.Site)=forms![Expenditure Plot Options]!cboSite) And ((Master.Exclude)=False));"
End If
End Sub
Last edited: