Server Filter

When developing on Forms using Microsoft Project, it is easy to accidentally set the Server Filter to one particular record.  This can be unnoticed until a user enters that form and a record comes up that they were not expecting.

To remove the need to check every form I have written a routine which checks every form and sets the Server filter to Null.

I have put a reset button on the Main_Menu.  This code therefore tells Access to ignore the Main_Menu Form and the Login Form

Private Sub btn_Reset_Click()

On Error GoTo CannotPerformOperation

Dim IsFormOpen As Boolean           'Check to see if any form is open
Dim accObj As AccessObject          'Will be set to Allforms object
Dim strForm As String                     'Individual form names so can indicate forms not to check
Dim frm As Form                             'Refer to individual form object


For Each accObj In CurrentProject.AllForms     'Go through ALL forms

IsFormOpen = accObj.IsLoaded     'Check to see if the current form is loaded
strForm = accObj.Name

If strForm <> "frmLogin" And strForm <> "Main_Menu" And IsFormOpen = True Then    'Do not include the login and main menu forms
DoCmd.Close acForm, strForm, acSaveNo                                                                 'If the form is currently open for viewing - close it
End If


IIf strForm = "Activity_Form" Or strForm = "Admission_Update_Form" _
Or strForm = "Assessment_Form" Or _
strForm = "Care_Plan_Archive_Form" Or _                                                                 'Include all the forms you would like to check
strForm = "Staff_Form_Admin" Then
DoCmd.OpenForm strForm, acDesign, WindowMode:=acHidden                                  'Open each form in design view

Set frm = Forms(strForm)
frm.ServerFilter = ""                                                                                                   'Set the Server filter to null

'etc for other properties

Set frm = Nothing                                               'Set the Form object back to nothing
DoCmd.Close acForm, strForm, acSaveYes         'Close the current form saving changes
End If
Next                                                                  'Go back and get the next form
MsgBox "Check Complete", vbInformation
Exit Sub
CannotPerformOperation:
MsgBox "Unable to complete the operation", vbCritical

End Sub