search form

J

jason

hello all, i have a question that is probly pretty easy
but i am not a really good coder so im lost.
i have a search form where i type in a string of text and
hit the search button. the search button is coded to open
another form that holds all my data and display matches
after looking through every text box. Lately i have added
a subform to the form that holds all my data and i cannot
figure out how to add to my search button code to tell it
to search the subform as well. here is the code to my
search button:

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Len(Me.Text0 & "") = 0 Then
MsgBox "Sorry try Again.", vbOKOnly, "Error"
Me.Text0.SetFocus


Else
stDocName = "SWDATA"
stLinkCriteria = "([SITE] Like ""*" & Me.Text0 & _
"*"") OR ([NUM] Like ""*" & Me.Text0 & _
"*"") OR ([SYSTEM] Like ""*" & Me.Text0 & _
"*"") OR ([NAME] Like ""*" & Me.Text0 & _
"*"") OR ([VER] Like ""*" & Me.Text0 & _
"*"") OR ([QUANTITY] Like ""*" & Me.Text0 & _
"*"") OR ([SN] Like ""*" & Me.Text0 & _
"*"") OR ([MGR] Like ""*" & Me.Text0 & _
"*"") OR ([DEPT] Like ""*" & Me.Text0 & _
"*"") OR ([STN] Like ""*" & Me.Text0 & _
"*"") OR ([DATE REC'D] Like ""*" & Me.Text0 & _
"*"") OR ([USER] Like ""*" & Me.Text0 & _
"*"") OR ([UPDATE/NEW] Like ""*" & Me.Text0 & _
"*"") OR ([STATUS] Like ""*" & Me.Text0 & _
"*"") OR ([PURCHASE #] Like ""*" & Me.Text0 & _
"*"") OR ([VENDOR] Like ""*" & Me.Text0 & _
"*"") OR ([SERVER] Like ""*" & Me.Text0 & _
"*"") OR ([COMMENTS] Like ""*" & Me.Text0 & "*"")"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Me.Text0.SetFocus

Exit Sub
Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub


What i need to know is how to add code to make it search a
subform on the same form.
can anyone help?
 
A

Allen Browne

For a short answer to your question, see:
Filter a Form on a Field in a Subform
at:
http://allenbrowne.com/ser-28.html

Your code example may not work well for dates and numbers, and is quite
inefficient if lots of the search text boxes are left blank. Dates need # as
the delimiter instead of quotes, and the Like probably won't work. Numbers
should not have the extra quotes.
 

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