Filter Properties cannot be empty.

atzdgreat

Member
Local time
Today, 11:45
Joined
Sep 5, 2019
Messages
42
Hi everyone. have you ever encountered that your filter properties in continuous form cannot be empty even though you already created code to empty filter. i experienced this when my form encountered error and the last query will automatically saved in filter properties.

Code:
Private Sub Form_Load()
    Me.FilterOn = False
    Me.Filter = ""
    Me.FilterOn = True
    Me.Requery
End Sub

i always manually remove the query from filter properties to make the process okay.
 
If you set the filter in the runtime environment (Form View), then switch to design mode (without closing the form first) and save the form, the filter is saved in the form design.
Deleting the filter only at runtime does not change the draft setting.

Could this be the cause of your problem?
 
Last edited:
If there is no valid filter value ( "" ) then the FilterOn = True will be ignored. It's not documented but is a weirdness of the filtering properties.
Try something like

Me.Filter = "1 = 1"
Me.FilterOn = True
 
If there is no valid filter value ( "" ) then the FilterOn = True will be ignored.
Tried it out briefly: Me.Filter = "" followed by Me.FilterOn = True shows all data records and Filter property is empty.
Property FilterOn is False (and not True as set in the code). <-- Is that what you meant?
=> ""/vbnullstring as filter value is applied (or delete the filter). I consider the fact that FilterOn is then set to False to be the correct value, as no filter is applied.

Test code:
Code:
Private Sub cmdTest_Click()

  If Me.Filter = "id=4" Then
    Me.Filter = vbNullString
  Else
    Me.Filter = "id=4"
  End If
  Me.FilterOn = True
'   I usually write it like this:
'   Me.FilterOn = len(me.Filter)>0)

  Debug.Print Me.Filter & " | " & Me.FilterOn

End Sub
 
Last edited:
Property FilterOn is false. <-- Is that what you meant?

Yes, I didn't explain it correctly. - the FilterOn property switches to false if there is no filter.
You have to turn it back on if you add a new valid filter condition.
 
the last query will automatically saved in filter properties
You can prevent the usage of the saved filter with Form.FilterOnLoad = False in forms property-sheet or in Form_Open event (more appropriate than Form_Load as that event fires after form with data is loaded).
 
If you set the filter in the runtime environment (Form View), then switch to design mode (without closing the form first) and save the form, the filter is saved in the form design.
Deleting the filter only at runtime does not change the draft setting.

Could this be the cause of your problem?
yes you are right. i dont know the reason why it doesnt delete the filter at runtime.
 

Users who are viewing this thread

Back
Top Bottom