+ Reply to Thread
Results 1 to 4 of 4

Userform.Caption is blank when reference passed to class

  1. #1
    NickHK
    Guest

    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



  2. #2
    Chip Pearson
    Guest

    Re: 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" <TungCheWah@Invalid.com> wrote in message
    news:%23Jg2bX9fGHA.3468@TK2MSFTNGP03.phx.gbl...
    > '** 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
    >
    >




  3. #3
    NickHK
    Guest

    Re: 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" <chip@cpearson.com> wrote in message
    news:%23znnKX$fGHA.1792@TK2MSFTNGP03.phx.gbl...
    > 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" <TungCheWah@Invalid.com> wrote in message
    > news:%23Jg2bX9fGHA.3468@TK2MSFTNGP03.phx.gbl...
    > > '** 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
    > >
    > >

    >
    >




  4. #4
    Andy Pope
    Guest

    Re: 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" <chip@cpearson.com> wrote in message
    > news:%23znnKX$fGHA.1792@TK2MSFTNGP03.phx.gbl...
    >
    >>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" <TungCheWah@Invalid.com> wrote in message
    >>news:%23Jg2bX9fGHA.3468@TK2MSFTNGP03.phx.gbl...
    >>
    >>>'** 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1