Userform.Caption is blank when reference passed to class

N

NickHK

'** In MyClass.cls
Private XLUForm As UserForm
Public Property Set XLUserForm(vData As UserForm)
Set XLUForm = vData
End Property

'**Called from a userform called MyForm
Set MyClass.XLUForm=MyForm

Using the above code in a class in same WB as the passed UserForm,
vData.Caption always evaluates to "".
But if, whilst in the class, I test ?MyForm.Caption it returns the correct
value.
Also, properties like vData.Width are no longer "supported", but
..InsideWidth is.

If I change the declarations to:
Private XLUForm As MyForm
Public Property Set XLUserForm(vData As MyForm)

everything is *normal*.

Anyone explain why ?

NickHK
 
C

Chip Pearson

A generic userform object has very few properties. Most
properties are created when the form is created.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
N

NickHK

Chip,
So if I wanted a generic routine in a class to deal with userforms e.g
'**MyFormClass
Public Function ReadCaption (argUserForm as UserForm)
MsgBox argUserForm.Caption
End Function

Calling this from a cmd on a userform:
Dim cFormHandler As MyFormClass
cFormHandler.ReadCaption Me

This will never work then because the object does not have such a property.
I can't create routines for every userform used, passing in the speciifc
userform, as in
Public Function ReadCaption (argUserForm as UserForm1)...
Public Function ReadCaption (argUserForm as UserForm2)...etc

NickHK
 
A

Andy Pope

This worked for me.

Public Function ReadCaption(argUserForm As Object)

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top