I have a form defaulted as Continuous Forms.
Here is my code in back of form.
Private Sub Form_AfterUpdate()
Dim x1 As String
Dim x2 As String
Dim strSQL As String
If Combo1.Value = "ALL" And Combo2.Value = "ALL" Then
strSQL = "SELECT [Personnel Combined Table].[Professional Title], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title];"
Else
If Combo1.Value = "ALL" And Combo2.Value <> "ALL" Then
x2 = "ALL"
x1 = Combo2.Value
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type] HAVING ((([Personnel Combined Table].[Agency Type])= " & Chr(34) & x1 & Chr(34) & ");"
GoTo QueryMaker
Else
If Combo1.Value <> "ALL" And Combo2.Value = "ALL" Then
x2 = Val(Right([Combo1], 2))
x1 = "ALL"
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[HHSC Region], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[HHSC Region] HAVING ((([Personnel Combined Table].[HHSC Region])= " & x2 & ");"
GoTo QueryMaker
Else
x1 = Combo2.Value
x2 = Val(Right([Combo1], 2))
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type],[Personnel Combined Table].[HHSC Region], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type],[Personnel Combined Table].[HHSC Region] HAVING ((([Personnel Combined Table].[Agency Type])= " & Chr(34) & x1 & Chr(34) & " AND (([Personnel Combined Table].[HHSC Region])= " & x2 & ");"
GoTo QueryMaker
End If
End If
End If
QueryMaker:
'Combo1.Value = x2
'Combo2.Value = x1
Me.RecordSource = strSQL
Me.Requery
strSQL = ""
I have no problem changing the values of the combobox if there are records that previously match the criteria.
When I select a combination when no records match the criteria, the values in the comboboxes are orphaned, not sticking. I am trying to reset the comboboxes when no records are found to allow the combobox to accept values again. When I try to reselect, the value is selected, but the bound field do not take place, becomes invisible and not selected. I hope I am making myself clear.
Any suggestions would be great.
Thanks in advance!!
Here is my code in back of form.
Private Sub Form_AfterUpdate()
Dim x1 As String
Dim x2 As String
Dim strSQL As String
If Combo1.Value = "ALL" And Combo2.Value = "ALL" Then
strSQL = "SELECT [Personnel Combined Table].[Professional Title], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title];"
Else
If Combo1.Value = "ALL" And Combo2.Value <> "ALL" Then
x2 = "ALL"
x1 = Combo2.Value
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type] HAVING ((([Personnel Combined Table].[Agency Type])= " & Chr(34) & x1 & Chr(34) & ");"
GoTo QueryMaker
Else
If Combo1.Value <> "ALL" And Combo2.Value = "ALL" Then
x2 = Val(Right([Combo1], 2))
x1 = "ALL"
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[HHSC Region], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[HHSC Region] HAVING ((([Personnel Combined Table].[HHSC Region])= " & x2 & ");"
GoTo QueryMaker
Else
x1 = Combo2.Value
x2 = Val(Right([Combo1], 2))
strSQL = "SELECT [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type],[Personnel Combined Table].[HHSC Region], Sum([Personnel Combined Table].[FTE Total Employees]) AS [FTE Total Employees], Sum([Personnel Combined Table].[FTE Total]) AS [FTE Total], Avg([Personnel Combined Table].[Average Annual Salary]) AS [Average Annual Salary], Max([Personnel Combined Table].[Maximum Annual Salary]) AS [Maximum Annual Salary], Min([Personnel Combined Table].[Minimum Annual Salary]) AS [Minimum Annual Salary]"
strSQL = strSQL & " FROM [Personnel Combined Table] GROUP BY [Personnel Combined Table].[Professional Title],[Personnel Combined Table].[Agency Type],[Personnel Combined Table].[HHSC Region] HAVING ((([Personnel Combined Table].[Agency Type])= " & Chr(34) & x1 & Chr(34) & " AND (([Personnel Combined Table].[HHSC Region])= " & x2 & ");"
GoTo QueryMaker
End If
End If
End If
QueryMaker:
'Combo1.Value = x2
'Combo2.Value = x1
Me.RecordSource = strSQL
Me.Requery
strSQL = ""
I have no problem changing the values of the combobox if there are records that previously match the criteria.
When I select a combination when no records match the criteria, the values in the comboboxes are orphaned, not sticking. I am trying to reset the comboboxes when no records are found to allow the combobox to accept values again. When I try to reselect, the value is selected, but the bound field do not take place, becomes invisible and not selected. I hope I am making myself clear.
Any suggestions would be great.
Thanks in advance!!