Filter Multiple fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to filter several fields in a subform, the main form contains
unbound fields which will supply the search criteria
Unfortunately I can't get past filtering more than one field, below is my
unsuccessful attempt.


Private Sub cmdFilterOn_Click()
Dim strSearch1 As String
Dim strSearch2 As String


strSearch1 = "Like '*' & cboCreatedBy.Value & '*'"
strSearch2 = "Like '*' & cboIncidentType.Value & '*'"


Form_frmHistory.Form.Filter = "[Created By]" & strSearch1 And "[Incident
Type]" & strSearch2

Form_frmHistory.Form.FilterOn = True

End Sub

Regards,
Duncan
 
DuncanG said:
I'm trying to filter several fields in a subform, the main form contains
unbound fields which will supply the search criteria
Unfortunately I can't get past filtering more than one field, below is my
unsuccessful attempt.

Private Sub cmdFilterOn_Click()
Dim strSearch1 As String
Dim strSearch2 As String

strSearch1 = "Like '*' & cboCreatedBy.Value & '*'"
strSearch2 = "Like '*' & cboIncidentType.Value & '*'"

Form_frmHistory.Form.Filter = "[Created By]" & strSearch1 And "[Incident
Type]" & strSearch2
Form_frmHistory.Form.FilterOn = True


Your quotes are all mixed up:

strSearch1 = "Like '*" & cboCreatedBy.Value & "*' "
strSearch2 = "Like '*" & cboIncidentType.Value & "*' "

Form_frmHistory.Form.Filter = "[Created By] " & strSearch1 _
& " And [Incident Type] " & strSearch2
Form_frmHistory.Form.FilterOn = True

Adding breakpoint on the last line will allow you to inspect
the result of all that concatenation and veirfy the Filter
final string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top