Macro/module to show form filter?

GopherUK

Active Member
Joined
Jan 23, 2009
Messages
473
Hi,

I am a bit stuck with this one... is it possible to create a macro/module that will display the form filter? I would also like one that would toggle the filter on and off. Is this possible?

Thanks in advance.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Here's a vba function that should give you the Filter for a Form.
'---------------------------------------------------------------------------------------
' Procedure : getFormFilters
' Author : Jack
' Date : 05-10-2011
' Purpose : To return the Filter expression for a supplied Form name
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: Form name
' Dependency: N/A
'--------------------------------------------------------------------------
'
Public Function getFormFilters(FrmName As String) As String

On Error GoTo getFormFilters_Error

If Not CurrentProject.AllForms(FrmName).IsLoaded Then
DoCmd.OpenForm FrmName, acNormal, , , , acHidden
getFormFilters = Forms(FrmName).Filter
DoCmd.Close acForm, FrmName
Else
getFormFilters = Forms(FrmName).Filter
End If

On Error GoTo 0
Exit Function
getFormFilters_Error:

MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure getFormFilters of Module AWF_Related"

End Function

In my test,
Debug.Print frm.name & vbCrLf & vbTab & "Filter: " & vbTab & getFormFilters(frm.name)
the result shows the Form name and the Filter on next line
Customer Orders
Filter: ((Customers.Country="Mexico"))
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,802
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top