Filter a form using a button (1 Viewer)

KThanos

New member
Local time
Today, 22:49
Joined
Apr 2, 2016
Messages
3
I have made an Access 2016 database, and I want to use it on PCs with Access 2013 Runtime which does not has filters (because Office 365 Business Premium does not include MS Access), so I need initially to create a button to filter the records by selection. To explain further, I want when a user selects a field (or part of a field), to list any records with that value. Thank you.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:49
Joined
Sep 21, 2011
Messages
14,310
Here is how I was filtering a form before I changed to using a query

HTH
Code:
' Now set the filter to get just the rows we want
    strFilter = "Yes"
    
    Me.Filter = "EmailStatus = """ & strFilter & """"
    Me.FilterOn = True

*** My processing code here ****

' Switch off the filter 
    Me.FilterOn = False
 

KThanos

New member
Local time
Today, 22:49
Joined
Apr 2, 2016
Messages
3
The above didn't work for me - it seems to be wrong. It clears the entire form like the selected field we are searching does not exist.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:49
Joined
May 7, 2009
Messages
19,245
don't use button, since when you click on the button, your textbox will lost its focus, therefore, if you highlight any text for filter, the highlight will disappear.

i suggest using function key (ie, Ctrl-F2 key) for your search:

on the field control you want to filter, put code on the MouseDown event:

Private Sub controlName_KeyDown(KeyCode As Integer, Shift As Integer)
Dim s As String
Dim c As Access.Control
If KeyCode = vbKeyF2 And (Shift And acCtrlMask) Then
Set c = Screen.ActiveControl
'if no highlighted text, clear the filter
If Trim(c.value & "") = "" Or c.SelLength = 0 Then
Me.FilterOn = False
Else
s = Mid(c.value, c.SelStart + 1, c.SelLength)
Me.Filter = "[" & c.Name & "] like " & Chr(34) & "*" & s & "*" & Chr(34)
Me.FilterOn = True
End If
End If
End Sub
 

Users who are viewing this thread

Top Bottom