Im (trying to) write some module-level code to perform operations on a form, with a control on the form being passed.
For the purposes of this demonstration, Im using a Frame, and passing the Frame object as a parameter to the sub, all inside the same module.
I was/am having a problem getting the (correct?) parent object of the frame. If I explicitly dim the parent as "MSForms.UserForm", or just "UserForm", I am unable to get the caption property of the form. But when i accidentally misspelled the Object variable in my DIM statement, which will now make the non-dimmed version of the variable a VARIANT, it works! (Take THAT, Option Explicit!)
Im not sure why this is working/not working. To reproduce this, Drop in a form, and a frame. Use the default naming for the Frame, "Frame1". Then drop this sub into the form module:
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub test(objFrame As Frame)
MsgBox objFrame.Parent.Caption ' this works, without getting the object
Dim tmpMSForm As MSForms.UserForm
Set tmpForm = objFrame.Parent 'if you change "tmpForm" to "tmpMSForm" as declared, it doesnt work!
MsgBox tmpForm.Caption
End Sub
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Call the sub from the userform.initialize event, passing the frame as a parameter:
Private Sub UserForm_Initialize()
test Frame1
End Sub
Notice that both message box calls work. But, in the "test" subroutine, if you change the undeclared "tmpForm" variable (Variant)
to "tmpMSForm" (declared as MsForms.Userform, or even declared as "UserForm"), the caption property comes back empty.
Why is this happening?