Private Function fGetParentForm(ctrlActiveControl As Control) As Form
Dim strSubName As String
Dim strModuleName As String
strSubName = "fGetParentForm"
strModuleName = "Module - clsCallCalled"
On Error GoTo Error_Handler
Dim ctlToTest As Control
Set ctlToTest = ctrlActiveControl 'Will Always be a "Control? No Not always... "
'/////////// CHECK THIS ...No Not always...
Dim X As Integer
For X = 1 To 20 'This will check to 20 levels
If Not fParentIsaForm(ctlToTest.Parent.Name) Then 'Is Parent a Form?
'It's not a form, so it must still be a control so carry on checking a "Control"
Set ctlToTest = ctlToTest.Parent 'No --- Then check the next Parent
Else
'It is a form, so you have found the form that the control is on.
Set fGetParentForm = ctlToTest.Parent 'Yes -- Then Set the Property to The Parent Form
Exit For
End If
Next X
'I cannot foresee a situation with more than 20 levels, but I thought a check on it would be wise
If X >= 20 Then MsgBox "Message from clsCallCalled ---" & "ERROR 20 Levels EXCEEDED, change 20 to a higher Figure ---", , conAppName
'////////// For Testing -
If prpFlgDevMode Then
MsgBox " >>> WARNING !!! --- DEVELOPER MODE IS ACTIVE!!!", , conAppName
MsgBox "Level Checked to is :- " & X & " Level(s)", , conAppName
End If
Exit_ErrorHandler:
Exit Function
Error_Handler:
Dim strErrFrom As String
Dim strErrInfo As String
strErrFrom = "Error From:-" & vbCrLf & strModuleName & vbCrLf & "Subroutine >>>>>>> " & strSubName
strErrInfo = "" & vbCrLf & "Error Number >>>>> " & Err.Number & vbCrLf & "Error Descscription:-" & vbCrLf & Err.Description
Select Case Err.Number
Case 1 'When Required, Replace Place Holder (1) with an Error Number
MsgBox "Error produced by Place Holder please check your code!" & vbCrLf & vbCrLf & strErrFrom & strErrInfo, , conAppName
Case Else
MsgBox "Case Else Error" & vbCrLf & vbCrLf & strErrFrom & strErrInfo, , conAppName
End Select
Resume Exit_ErrorHandler
End Function 'fGetParentForm