form filter via vba/macro

georg7

Registered User.
Local time
Today, 14:16
Joined
Sep 3, 2019
Messages
84
Good morning guys,
I would like to have the form filtered using a button. For example, if I press filter 1, NM should be filtered to ZN.(Form.png)
I've read many threads but couldn't get it to work...
May some of you guys can help me.

Appreciate it!

Best regards
Georg
 

Attachments

  • Form.PNG
    Form.PNG
    25.7 KB · Views: 150
  • Table.PNG
    Table.PNG
    10.8 KB · Views: 144
Private Sub Filter1()
Me.Filter = "NM = 'ZN'"
Me.FilterOn = True
End Sub



I've to admit that i'm not very confident with vba in Access.
 
I wrote it in the VBA Code of button "Filter 1".
 
Have checked that the code does actually fire when the button is clicked
 
PMFJI, but if you had put that in the click event of the button, the name of the Sub would reflect that.?
Indeed, which is why I asked about the code actually running as I would expect an error message if it did. From the picture posted by the OP the button appears to be on a main form
 
The query is called Test1 and the Sub form is called Test1-Unterformular
 
Try

Me!Subform1.Form. [Test1-Unterformular].Filter = "NM = 'ZN'"
Me!Subform1.Form. [Test1-Unterformular].FilterOn = True
 
What does Subform1.form mean?
Is it the Name of the form i want the filter button on?
 
No. Sorry, Should be the name of the subform control on the main form. So try
Me![Test1-Unterformular].Form.Filter = "NM = 'ZN'"
Me![Test1-Unterformular].Form.FilterOn = True
 
Do you know how to connect it with a drop down bar? Where I can pick the NM Value that should be the criteria ?
 

Users who are viewing this thread

Back
Top Bottom