csmithjr87
csmithjr87

Reputation: 3

Access 2013 - Textbox searching in two fields

I have a simple database for tracking incidents at work. On the main form is a subform that shows a brief overview of all events logged.

I have a search box in the subform's header that searches keywords in the "Details" field, but I would like it to also search in the "Location" field of the subform at the same time.

My code is:

Private Sub Text18_Change()
Dim strFilter As String

Me.Refresh

strFilter = "Details like '*" & Me.Text18 & "*'"

Forms![Main Form]![MainIncidentList].Form.Filter = strFilter
Forms![Main Form]![MainIncidentList].Form.FilterOn = True

Me.Text18.SelStart = Nz(Len(Me.Text18), 0)
End Sub

I'm relatively new at Access and VBA but I've gotten this far, can anyone give me some advice on how to add the "Location" field to the search? I've tried adding

" And "Location like '*" & "Me.Text18 & "*'"

at the end of the "strFilter" line, but it did not work, Access gives a syntax error.

Both "Details" and "Location" are defined as "long text" in the table.

Thanks in advance.

Upvotes: 0

Views: 57

Answers (1)

Sergey S.
Sergey S.

Reputation: 6336

Try this:

strFilter = "Details like '*" & Me.Text18 & "*' OR Location like '*" & Me.Text18 & "*'"

Upvotes: 1

Related Questions