Cosmo
06-27-2008, 09:10 AM
I need to run a function (function 'add' in the code) on a MultiPage in a UserForm, and run the same function for every Page. Since both functions I have listed here need to be run on multiple object types (UserForm, MultiPage, Page), the parameters are passed as generic object type. I am checking the type of control (MultiPage or Page) by using TypeName(item) and find that when I call the function with a 'Page', it changes to type 'Controls' in the recursive function.
Here are the parts of the code to show the problem (NOTE - there is a lot more code involved, I have removed the function steps that I perform on the items to show just the recursion)
Private Function test()
Add UserForm1.MultiPage1
End Function
Public Function Add(ByRef Item As Object)
On Error GoTo errorcode
Dim oPage As Page
Dim objectType As String
Debug.Print "Item is type '" & TypeName(Item) & "'."
objectType = processItem(Item)
If TypeOf Item Is MultiPage Then
Dim i As Integer
Dim oMultipage As MultiPage
Set oMultipage = Item
For i = 1 To oMultipage.Pages.Count
Set oPage = oMultipage.Pages(i - 1)
Debug.Print "Page '" & oPage.Name & "' is type '" & TypeName(oPage) & "'."
Add (oPage)
Next i
End If
Debug.Print "Item is now type '" & TypeName(Item) & "'."
Debug.Print
Exit Function
errorcode:
Debug.Print "DialogCollection.Add - " & Err.Description
Resume Next
End Function
Private Function processItem(ByRef theObject As Object) As String
On Error GoTo errorcode
' NOTE-processing steps removed - this function recurses too.
Debug.Print "theObject is type '" & TypeName(theObject) & "'."
processItem = TypeName(theObject)
Exit Function
errorcode:
Debug.Print "Error processItem - " & Err.Description
processItem = ""
Resume Next
End Function
Here are the parts of the code to show the problem (NOTE - there is a lot more code involved, I have removed the function steps that I perform on the items to show just the recursion)
Private Function test()
Add UserForm1.MultiPage1
End Function
Public Function Add(ByRef Item As Object)
On Error GoTo errorcode
Dim oPage As Page
Dim objectType As String
Debug.Print "Item is type '" & TypeName(Item) & "'."
objectType = processItem(Item)
If TypeOf Item Is MultiPage Then
Dim i As Integer
Dim oMultipage As MultiPage
Set oMultipage = Item
For i = 1 To oMultipage.Pages.Count
Set oPage = oMultipage.Pages(i - 1)
Debug.Print "Page '" & oPage.Name & "' is type '" & TypeName(oPage) & "'."
Add (oPage)
Next i
End If
Debug.Print "Item is now type '" & TypeName(Item) & "'."
Debug.Print
Exit Function
errorcode:
Debug.Print "DialogCollection.Add - " & Err.Description
Resume Next
End Function
Private Function processItem(ByRef theObject As Object) As String
On Error GoTo errorcode
' NOTE-processing steps removed - this function recurses too.
Debug.Print "theObject is type '" & TypeName(theObject) & "'."
processItem = TypeName(theObject)
Exit Function
errorcode:
Debug.Print "Error processItem - " & Err.Description
processItem = ""
Resume Next
End Function