I desire listbox to display this format:
2016A(Base)
2016B(Adj)
2016C(2016A(Base)+2016B(Adj))
2017D(Base)
2017E(Adj)
2017F(2017D(Base)+2017E(Adj))
2017G(Base)
2017H(Adj)
2017I(2017G(Base)+2017H(Adj))
How do I get code to build query to recognize 2016C, 2017F and 2017I and feed query as cumulative? Currently query works if I choose 2016A or 2016B or 2016A and 2016B together.
Results are In('2016A') or In('2016B') or In ('2016A','2016B'). I want to be able to display 2016C in list box and the results when selected would be as if both 2016A and 2016B were
selected ie. results in strCriteria would be In('2016A','2016B'). Also, I would like 2017F and 2017I to give cumulative results and display 2017F and 2017I in listbox to be available
for selection. I want the flexibility to use this for 2018 and 2019 because scenario will be the same.
Code is below;
Private Sub cmd_filter_timeframe_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("qry_actTimeframe")
' Loop through the selected items in the list box and build a text string
For Each varItem In Me!lst_act_timeframe.ItemsSelected
strCriteria = strCriteria & ",'" & Me!lst_act_timeframe.ItemData(varItem) & "'"
Next varItem
' Check that user selected something
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT tbl_A_CFS_Scenario.act_Timeframe FROM tbl_A_CFS_Scenario " & _
"WHERE tbl_A_CFS_Scenario.act_Timeframe IN(" & strCriteria & ");"
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub
2016A(Base)
2016B(Adj)
2016C(2016A(Base)+2016B(Adj))
2017D(Base)
2017E(Adj)
2017F(2017D(Base)+2017E(Adj))
2017G(Base)
2017H(Adj)
2017I(2017G(Base)+2017H(Adj))
How do I get code to build query to recognize 2016C, 2017F and 2017I and feed query as cumulative? Currently query works if I choose 2016A or 2016B or 2016A and 2016B together.
Results are In('2016A') or In('2016B') or In ('2016A','2016B'). I want to be able to display 2016C in list box and the results when selected would be as if both 2016A and 2016B were
selected ie. results in strCriteria would be In('2016A','2016B'). Also, I would like 2017F and 2017I to give cumulative results and display 2017F and 2017I in listbox to be available
for selection. I want the flexibility to use this for 2018 and 2019 because scenario will be the same.
Code is below;
Private Sub cmd_filter_timeframe_Click()
' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("qry_actTimeframe")
' Loop through the selected items in the list box and build a text string
For Each varItem In Me!lst_act_timeframe.ItemsSelected
strCriteria = strCriteria & ",'" & Me!lst_act_timeframe.ItemData(varItem) & "'"
Next varItem
' Check that user selected something
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT tbl_A_CFS_Scenario.act_Timeframe FROM tbl_A_CFS_Scenario " & _
"WHERE tbl_A_CFS_Scenario.act_Timeframe IN(" & strCriteria & ");"
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub