I like the orange version better for its simplicity. RobOtowski, if I understood your first post, you still won't have the ability to perform AND and OR approaches unless you provide separate sql constructs, which I see as being option button values passed to an option frame. Sorry if I've misunderstood your need. So you can have the benefit (?) of another method, here's how I have approached this in the past, using orange's code as a starting point:
Code:
Dim SQL As String, svCrit As String, svOrderBy As String
SQL = "SELECT * from Voters WHERE "
svOrderBy = " ORDER By VoterLastname"
If Frame1 = 1 Then 'option for records must contain all criteria supplied
If Me.txtFirstName = vbNullString Then Me.txtFirstName = "*"
If Me.txtLastName = vbNullString Then Me.txtLastName = "*"
If Me.cboDistrict = vbNullString Then Me.cboDistrict = "*"
svCrit = "VoterFirstname Like '" & Me.txtFirstName & "*' AND VoterLastname Like '"
svCrit = svCrit & Me.txtLastName & "*' AND VoterDistrict Like '*" & Me.cboDistrict & "'"
Else 'option for records will contain any criteria supplied
svCrit = "VoterFirstName = '" & Me.txtFirstName & "' OR VoterLastName = '"
svCrit = svCrit & Me.txtLastName & "' OR voterAddrSt = '" & Me.cboDistrict & "'"
End If
SQL = SQL & svCrit & svOrderBy
' Debug.Print SQL
Me.VoterSubform.Form.RecordSource = SQL
Me.VoterSubform.Form.Requery
Me.txtRecs = DCount("ID", "Voters", svCrit)
End Sub
This is how I've constructed various sql statements based on user options where an AND, OR or even a UNION sql statement. Option button labels might explain that "Records returned will include ALL criteria options supplied" vs "Records returned will include ANY criteria options supplied" or something like that. My option button values are 1 and 2 respectively. The chosen value gets passed to the frame, which I simply named Frame1. Note the insertion points for spaces are different in the clauses. I have left out the wildcards for simplicity, so as written, it requires exact matches (i.e. Av will not return Ava). Also, I would set the option on form opening so that a user will not cause an error by not selecting an option:
Code:
Private Sub Form_Open(Cancel As Integer)
Me.Frame1 = 1
End Sub