Search at once in 2 fileds of the same table

F

Frank Situmorang

Hello,

Here is my VBA, how can I make it to search in 2 fileds, but we just type in
at once in the textbox of search.

Private Sub Txtcari_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*" &
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.Txtcari & "*" & """)"
'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub

Thanks for any help.

Frank
 
M

Marshall Barton

Frank said:
Here is my VBA, how can I make it to search in 2 fileds, but we just type in
at once in the textbox of search.

Private Sub Txtcari_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*" &
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.Txtcari & "*" & """)"
'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub


If you want to match both fields then use AND:

strFilter = "Nota LIKE ""*" & Me.Txtcari & "*"" AND
otherfield LIKE ""*" & Me.Txtcari & "*"" "

If you want to match either one or both, use OR:

strFilter = "Nota LIKE ""*" & Me.Txtcari & "*"" OR
otherfield LIKE ""*" & Me.Txtcari & "*"" "
 
F

Frank Situmorang

Marsh:

Thanks for your response. I want to use OR, but when I copy paste it and
change the other filed into the actual name, there is a syntax error.

Anyway, can you tell me why you deleted [ ] bracket sign?, txtcari is the
name of the unbound textbox where we type the word searched.

Moreover... my Minutes of meeting database consists of 2 table, 1 is
Meetingdate table and the other is Minutes of meeting. The Nota field and the
subject field ( the other field) are in the MOM ( Minutes of Meeting) table.
My form is the mother form linked to childform (Mom).

Thanks again for your explaining again.

Frank

Marshall Barton said:
Frank said:
Here is my VBA, how can I make it to search in 2 fileds, but we just type in
at once in the textbox of search.

Private Sub Txtcari_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*" &
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.Txtcari & "*" & """)"
'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub


If you want to match both fields then use AND:

strFilter = "Nota LIKE ""*" & Me.Txtcari & "*"" AND
otherfield LIKE ""*" & Me.Txtcari & "*"" "

If you want to match either one or both, use OR:

strFilter = "Nota LIKE ""*" & Me.Txtcari & "*"" OR
otherfield LIKE ""*" & Me.Txtcari & "*"" "
 
M

Marshall Barton

If you want someone to analyze what you did, you should post
a Copy/Paste of it so we can see what you currently have.

The [ ] are only required when there is a non alphanumeric
character in the name. I never create names that require
the [ ] and leave them out to save typing.

Your Mom table is the child table and your mother form is
the ??? form? Are you trying to say that the search text
boxes and the code are in ??? form and you want to filter
the Mom subform? If so, then you have to set the subform's
Filter property:
Me.subformcontrolname.Form.Filter = strFilter
Me.subformcontrolname.Form.FilterOn = True
--
Marsh
MVP [MS Access]


Frank said:
Thanks for your response. I want to use OR, but when I copy paste it and
change the other filed into the actual name, there is a syntax error.

Anyway, can you tell me why you deleted [ ] bracket sign?, txtcari is the
name of the unbound textbox where we type the word searched.

Moreover... my Minutes of meeting database consists of 2 table, 1 is
Meetingdate table and the other is Minutes of meeting. The Nota field and the
subject field ( the other field) are in the MOM ( Minutes of Meeting) table.
My form is the mother form linked to childform (Mom).
If you want to match either one or both, use OR:

strFilter = "Nota LIKE ""*" & Me.Txtcari & "*"" OR
otherfield LIKE ""*" & Me.Txtcari & "*"" "
 

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

Top