Change list to combo box

  • Thread starter Thread starter sharon.brubaker
  • Start date Start date
S

sharon.brubaker

Guest
I have a list box that uses the following code to open a filtered form based on the item selected:
_______________________________________

Private Sub Command5_Click()
Dim DivFilter As String
Dim frm As Form
Dim ctl As Control
Dim varItm As Variant

Set frm = Forms!frmDivisionPopup
Set ctl = frm!List0

For Each varItm In ctl.ItemsSelected
strDivision = ctl.ItemData(varItm)
Next varItm

DivFilter = "org = '" & strDivision & "'"
DoCmd.Close acForm, "frmDivisionPopup", acSaveNo
Select Case strOpenForm
Case "BaseBudget"
DoCmd.OpenForm "frm01inputdetailtest", , "qryBudgetInputCosts", DivFilter
Case "Carryover"
DoCmd.OpenForm "frmCarryoverInput", , "qryCarryoverrequestinput", DivFilter
Case "Supps"
DoCmd.OpenForm "frmSupplementalInput", , "qrysupprequestinput", DivFilter

End Select
End Sub
_______________________________________

I have been asked to change this from a list box to a combo box…

Does anyone know how to pass the selected value from the combo box on to the filter?

I have spent the entire day trying different variations of the above code with no luck.
 
the only bit that should need changing is


Set frm = Forms!frmDivisionPopup
Set ctl = frm!List0

For Each varItm In ctl.ItemsSelected
strDivision = ctl.ItemData(varItm)
Next varItm

DivFilter = "org = '" & strDivision & "'"

to whatever you called the combo box

Set frm = Forms!frmDivisionPopup
strDivision = ctl.CboMyData

DivFilter = "org = '" & strDivision & "'"


HTH

Peter
 
In general, to refer to ComboBox values instead of the ".itemdata" property you use the ".value" one. That works when you have a single column in the ComboBox, or if you have more than one but the value is stored in the dependent one.
"BUT"
If you have two or more columns and the value you want to take is not in the dependent column (you can see which is the dependent column in the design view of the form, data properties of your ComboBox) you have to refer to this value through the ".Column(X)" property, being "X" the number of the column which has the value minus 1 (the columns are numbered starting from 0, so the first column is .column(0), the second .column(1) and so on).

Good luck...
 

Users who are viewing this thread

Back
Top Bottom