Filters 2

ryetee

Registered User.
Local time
Today, 17:01
Joined
Jul 30, 2013
Messages
965
I asked this question before but focused on something that has now become irrelevant.
I Have a number of forms which either display the whole table/query or a predefined subset.
The form is continuous. The user wants to be able to search on specific columns for a string. I've pointed out he can right click and select a filter and do all of sophisticated things but he wants to type a string into a box, press a button and return, say for example, all customers that have "Ltd" in their name. I'm not sure how to do this. Can I put this in the form header and reload the page with some query?
 
I think you'd need to decide on what user action he'd like to initiate the search and start from there, since he doesn't like the idea of a right click. Probably all kinds of methods could be suggested, many of which may not be "liked" by user. I could say 'upon double click of column header, open an input form with a textbox for entry, and wrap it in LIKE operator" but the reply might be "he doesn't want to click on the headers). Know what I mean?
 
I agree. Knowing user specific requirements would be key. Would it be okay to have a search box constantly displayed on the form or does the user prefers a popup? Would the search always be performed on the same specific columns or different each time?
 
I think you'd need to decide on what user action he'd like to initiate the search and start from there, since he doesn't like the idea of a right click. Probably all kinds of methods could be suggested, many of which may not be "liked" by user. I could say 'upon double click of column header, open an input form with a textbox for entry, and wrap it in LIKE operator" but the reply might be "he doesn't want to click on the headers). Know what I mean?

he wants a "find" box in the header which he wants to type his search and then click the find button. i'm not sure how to code to reload the form based on a like operation.
 
He could use the build in "Find".
Code:
DoCmd.RunCommand acCmdFind
 
Where:
Me!txtSearch = Text field with text to find
Me!objSubForm.Form = Link to object - SubForm (or current continious form = Me.Form )
use at AfterUpdate avent - of search text field (Me!txtSearch)...

Code:
Private Sub txtSearch_AfterUpdate()
Dim val As Variant
Dim strFilter As String

On Error GoTo txtSearch_AfterUpdateErr

    val = Me!txtSearch
    
    If IsNull(val) = False Then 'There is some text - we will search for
    
    Me!objSubForm.Form.FilterOn = False 'Building of filter string with Like operator (match any part of the field)
        strFilter = "[Name of fied for search] Like '*" & val & "*'" 'Filter string
        Me!objSubForm.Form.Filter = strFilter
        Me!objSubForm.Form.FilterOn = True
        Me!objSubForm.SetFocus
    Else
    'Disable filter
        Me!objSubForm.Form.Filter = ""
        Me!objSubForm.Form.FilterOn = False
        Me!objSubForm.SetFocus
    End If

txtSearch_AfterUpdateBye:
    Exit Sub
    
txtSearch_AfterUpdateErr:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure txtSearch_AfterUpdate", vbCritical, "Error!"
    Resume txtSearch_AfterUpdateBye
End Sub
 
Last edited:
Have a look at these examples on allen Browne's website:
Search form
Find as you type
Highlight search matches


Finally got around to implementing this. I used "Find as you type". Had a slight problem which threw out an error. It fell over when trying to deal with a control called "Emptycellxxxx". As far as I know my form didn't have such a control. I put in some code to ignore these controls and it works a treat. Thanks.
 

Users who are viewing this thread

Back
Top Bottom