turning single freetext on change search to a multiple criteria search (1 Viewer)

splreece

Registered User.
Local time
Today, 02:21
Joined
Jun 2, 2016
Messages
40
Afternoon all.

I am a relative newbee so I may be asking something that can't be done easily, however, I have been successfully using the below search script for a while which has been fantastic (thank you access.programmers.co.uk). However the challenge is now, to create a search script amendment that adds an additional 3 search fields into the mix.


Is there a recommended way of adding the additional fields?

The additional fields are all combo's and they need 'and' clauses with them. So effectively the user can limit the search results before using the freetext "SrchText" field.


Combo boxes to be added are:

"cbo_country"
"cbo_channel"
"cbo_tag1"

so ideally the user can select the country and channel and tag1 and that will limit results before entering the "SrchText" .



'Create a string (text) variable
Dim vSearchString As String

'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = SearchFor.Text

'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll

SrchText.Value = vSearchString

'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
Me.SearchResults.Requery


'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor

If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor,
'and restores trailing space lost when focus is shifted to the list box

Me.SearchFor = vSearchString
Me.SearchFor.SetFocus
Me.SearchFor.SelStart = Me.SearchFor.SelLength

Exit Sub
End If

'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus

'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery

'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus

If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:21
Joined
Jul 9, 2003
Messages
16,352
I have compiled three sets of YouTube videos (Play Lists) which demonstrate how to build your own search form from scratch...

If you watch the last set of videos first:- Microsoft Access - Easy Search Criteria

You will see an example with option groups.

The three play lists cover the subject of a search form from a simple example to a reasonably sophisticated solution. You should be able to find a level that suits you.

MS Access - Building Search Criteria
MS Access - Building Advanced Search Criteria
Microsoft Access - Easy Search Criteria


If you get stuck and need help, then post the video url and the time index and I can, advise you...


Sent from my SM-G925F using Tapatalk
 

Users who are viewing this thread

Top Bottom