Hi,
I have a database with tables and fields. I have created a form that with three to four combo boxes and inserted a control button.
I would like a write a code to query my data based on the selection(s) made from the combo boxes when I click the command button.
I have this code and it is working perfectly well, only that I have created multiple command button to perform the queries I need.
Here is what I have:
In my code, I have two combo boxes but before the control works, I must make both selections. What code can I include that if I make only one selection and click the command button, I still get the query of my selection.
Any idea will be useful.
I have a database with tables and fields. I have created a form that with three to four combo boxes and inserted a control button.
I would like a write a code to query my data based on the selection(s) made from the combo boxes when I click the command button.
I have this code and it is working perfectly well, only that I have created multiple command button to perform the queries I need.
Here is what I have:
Code:
Dim Filter As String
Dim strProgram As String, strCohort As String, strCounty As String
If Me![cboSProgram] = "Select Program" Then Exit Sub
If IsNull(Me![cboSProgram]) Then Exit Sub
If Me![cboSCohort] = "Select Cohort" Then Exit Sub
If IsNull(Me![cboSCohort]) Then Exit Sub
If Me![cboSCounty] = "Select County" Then Exit Sub
If IsNull(Me![cboSCounty]) Then Exit Sub
strProgram = Nz(Me.cboSProgram, "*")
strCohort = Nz(Me.cboSCohort, "*")
strCounty = Nz(Me.cboSCounty, "*")
Filter = "strProgram = """ & cboSProgram & """ And strCohort = """ & cboSCohort & """ And strCounty = """ & cboSCounty & """"
DoCmd.OpenForm "tblSortSchools", acFormDS, , Filter
cboSProgram = "Select Program"
cboSCohort = "Select Cohort"
cboSCounty = "Select County"
cboSCohort.Requery
cboSCounty.Requery
Any idea will be useful.
Comment