crescent-centre
Registered User.
- Local time
- Today, 05:08
- Joined
- Feb 28, 2003
- Messages
- 30
I have a database of documents with title, reference number etc. I want to generate a search from the input form on any one of a number of fields. Currently I have to have a number of boxes on the form, one for each field then pass this into VB in the following format
Dim searchstring As String
searchstring = ""
TxtTitle.SetFocus
If TxtTitle.Text <> "" Then
searchstring = "(DrawingTitle Like ""*" & TxtTitle.Text & "*"")"
End If
TxtRefNumber.SetFocus
If TxtRefNumber.Text <> "" Then
If searchstring <> "" Then searchstring = searchstring & " And "
searchstring = searchstring & "(RefNumber like ""*" & TxtRefNumber.Text & "*"")"
End If
I then pass this to a report with the following
DoCmd.OpenReport "Search Query Results", acViewPreview, , searchstring
Problem is the more fields I want to search on the bigger the form and the longer the VBA.
How can I have one search box which checks against title and/or number and/or any other fields I add.
Dim searchstring As String
searchstring = ""
TxtTitle.SetFocus
If TxtTitle.Text <> "" Then
searchstring = "(DrawingTitle Like ""*" & TxtTitle.Text & "*"")"
End If
TxtRefNumber.SetFocus
If TxtRefNumber.Text <> "" Then
If searchstring <> "" Then searchstring = searchstring & " And "
searchstring = searchstring & "(RefNumber like ""*" & TxtRefNumber.Text & "*"")"
End If
I then pass this to a report with the following
DoCmd.OpenReport "Search Query Results", acViewPreview, , searchstring
Problem is the more fields I want to search on the bigger the form and the longer the VBA.
How can I have one search box which checks against title and/or number and/or any other fields I add.