UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> IsParentForm    

Occasionally, we may have a Form object that may be used either by itself or as a source for a subform. In such situations, attempting to refer to form's Parent property will result in a runtime error. This functions provides a simple test so code that are meant to be run whenever form is opened as subform and not when it's opened by itself without any errors.

CODE
' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use it in any application,
' provided this copyright notice is left unchanged.

Public Function IsParentForm(frm As Form) As Boolean
On Error GoTo Err_IsParentForm

If Not frm.Parent Is Nothing Then
   IsParentForm = False
End If

Exit_Procedure:
   Exit Function
Err_IsParentForm:
   Select Case Err.Number
       Case 2452
           IsParentForm = True
       Case Else
           MsgBox Err.Number & ", " & Err.Description
   End Select
   Resume Exit_IsParentForm
End Function


Example Usage:

CODE
If Not IsParentForm(Me) Then
  'Requery the whole form, not just the subform
  Me.Parent.Requery
End If


Creative Commons License
IsParentForm by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,562 times.  This page was last modified 09:38, 6 April 2011 by Jack Leach. Contributions by BananaRepublic  Disclaimers