ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform.Caption is blank when reference passed to class (https://www.excelbanter.com/excel-programming/362391-userform-caption-blank-when-reference-passed-class.html)

NickHK

Userform.Caption is blank when reference passed to class
 
'** 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



Chip Pearson

Userform.Caption is blank when reference passed to class
 
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

"NickHK" wrote in message
...
'** 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





NickHK[_2_]

Userform.Caption is blank when reference passed to class
 
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


"Chip Pearson" wrote in message
...
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

"NickHK" wrote in message
...
'** 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







Andy Pope

Userform.Caption is blank when reference passed to class
 
This worked for me.

Public Function ReadCaption(argUserForm As Object)

Cheers
Andy

NickHK wrote:
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


"Chip Pearson" wrote in message
...

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

"NickHK" wrote in message
.. .

'** 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







--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


All times are GMT +1. The time now is 09:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com