Microsoft Wiki

Checkout our wiki's socials

READ MORE

Microsoft Wiki

Filter/OpenArgs Validation[]

  • Three Code Snippets to help with Validating either Filter or OpenArgs values.[1][2]

NoFilterOrOpenArgs[]

Combination Method that utilizes NoFilter and NoOpenArgs to provide a summary of both methods.
Useful if you map this method directly to the Forms Event in the Properties panel while in GUI view, instead of VBA.

'@nm - String value, Name of the Form
Public Function NoFilterOrOpenArgs(nm As String)
    If NoFilter(Forms(nm), False) Or NoOpenArgs(Forms(nm), False) Then
        RaiseAlert "A Form was passed a OpenArgs and/or Filter value!" & vbCrLf & _
                    "This is not allowed, due to the nature of the Form." & vbCrLf & vbCrLf & _
                    "Form: " & nm & vbCrLf & vbCrLf & _
                    "Please advised you IT Support for assistance in resolving this error."
    End If
End Function


NoFilter[]

Check to see if a Filter has been applied to the Form and alerts the user that the Form does not allow for Filtering.

'@nm - String value, Name of the Form
'@show - Boolean value
'Notes:
'   - This method will validate whether the specified form (@frm) was passed a Filter value set.
'   - If @show is True (default) then a Message box will pop up alerting the user
'   - If @show is False then NoFilter will return True
Public Function NoFilter(nm As String, Optional show As Boolean = True)
    If Forms(nm).Filter & "" <> "" Then
        If show Then
            RaiseAlert "Filter has been applied to a form that is not allowed!" & vbCrLf & vbCrLf & _
                        "Form: " & nm & vbCrLf & vbCrLf & _
                        "Please advise your IT Support for assistance in resolving this error."
        Else
            NoFilter = True
        End If
    End If
End Function


NoOpenArgs[]

Checks to see if an OpenArgs value was passed to the Form and alerts the user that the Form does not allow for OpenArgs values.

'@nm - String value, Name of the Form
'@show - Boolean value
'Notes:
'   - This method will validate whether the specified form (@nm) was passed a OpenArgs value set.
'   - If @show is True (default) then a Message box will pop up alerting the user
'   - If @show is False then NoOpenArgs will return True
Public Function NoOpenArgs(nm As String, Optional show As Boolean = True)
    If Forms(nm).OpenArgs & "" <> "" Then
        If show Then
            RaiseAlert "Open Arguments has been passed to a form that only recognizes Filters!" & vbCrLf & vbCrLf & _
                        "Form: " & nm & vbCrLf & vbCrLf & _
                        "Please advise your IT Support for assistance in resolving this error."
        Else
            NoOpenArgs = True
        End If
    End If
End Function


IsOpen[]

  • Shows if a form is open or not.[3] Used in Show Snippet to perform a wait algorithm.

Public Function IsOpen(nm As String, Optional obj As Integer = acForm) As Boolean
    IsOpen = (SysCmd(acSysCmdGetObjectState, obj, nm) <> 0)
End Function


Show[]

  • Shows a form and then waits till the form is closed, to then perform further actions[4]

Public Sub ShowForm(par As Form, nm As String)
    DoCmd.OpenForm (nm)
    
    While IsOpen(nm)
        DoEvents
    Wend
    
    ... Perform post close processing ...
End Sub


Refresh Forms[]

  • Iterates through all loaded forms (as Access Objects) and performs a Requery & Refresh[5]

Public Sub RefreshForms()
    Dim frm As AccessObject
    For Each frm In CurrentProject.AllForms
        If frm.IsLoaded Then
            frm.Requery
            frm.Refresh
        End If
    Next frm
End Sub


References[]