I have this Filtering system that creates custom queries. The form has combo boxes for users to input criteria which they specify for a Query.
I want to save the Query as well.
For example, following values are entered by the user:
BranchName = Blossom
Year = 2005
Month = 12
It will Pull those values from the Query only and will save that Query as "Blossom" which is the Branch Name and is the value of a combo box named cboBranch.Value
[blue]
OBJ: -I want to Run the Query based on that Criteria
-I want Access to save that Query
-The name of that Query should be the same as
the value in the combo box cboBranchValue.
[/blue]
Private Sub cmdGo_Click()
Dim BranchName As String
Dim Month As Integer
Dim Year As Integer
Dim SQL As String
Dim db As Database
BranchName = cboBranch.Value
Month = cboMonth.Value
Year = cboYear.Value
SQL = SQL & "SELECT A.BID, A.CID, A.Branch, A.Month, "
SQL = SQL & "A.Year, A.[Total Members], A.PST, A.EBT, "
SQL = SQL & "(PST-EBT)/EBT As CHANGE, "
SQL = SQL & "(PST-EBT)*[Total Members]*12 As VARIANCE"
SQL = SQL & "FROM BranchInfoTable As A"
SQL = SQL & "WHERE A.Month =" & Month & ""
SQL = SQL & " And A.Year =" & Year & ""
SQL = SQL & " And A.Branch =" & Branch & ""
SQL = SQL & "ORDER BY A.PID;"
Set db = CurrentDb
db.QueryDefs("Blossom Query").SQL = SQL
End Sub
I want to save the Query as well.
For example, following values are entered by the user:
BranchName = Blossom
Year = 2005
Month = 12
It will Pull those values from the Query only and will save that Query as "Blossom" which is the Branch Name and is the value of a combo box named cboBranch.Value
[blue]
OBJ: -I want to Run the Query based on that Criteria
-I want Access to save that Query
-The name of that Query should be the same as
the value in the combo box cboBranchValue.
[/blue]
Private Sub cmdGo_Click()
Dim BranchName As String
Dim Month As Integer
Dim Year As Integer
Dim SQL As String
Dim db As Database
BranchName = cboBranch.Value
Month = cboMonth.Value
Year = cboYear.Value
SQL = SQL & "SELECT A.BID, A.CID, A.Branch, A.Month, "
SQL = SQL & "A.Year, A.[Total Members], A.PST, A.EBT, "
SQL = SQL & "(PST-EBT)/EBT As CHANGE, "
SQL = SQL & "(PST-EBT)*[Total Members]*12 As VARIANCE"
SQL = SQL & "FROM BranchInfoTable As A"
SQL = SQL & "WHERE A.Month =" & Month & ""
SQL = SQL & " And A.Year =" & Year & ""
SQL = SQL & " And A.Branch =" & Branch & ""
SQL = SQL & "ORDER BY A.PID;"
Set db = CurrentDb
db.QueryDefs("Blossom Query").SQL = SQL
End Sub