Unanswered: Use a single control to query more fields or combo boxes
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:
Private Sub cmdGetRecord_Click()
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"
In my code, I have three combo boxes but before the control works, I must make selections in all boxes. 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.