Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    Class and Userforms (2000 SR1)

    WIthin an Excel Addin I have a Class that performs some file IO. The actions and locations for the IO performed are determined by input from the user via a UserForm. What is the best way to handle gathering the input from the UserForm to be used by the Class object?
    I have tried within the class to create a new instance of the form
    Dim frm as frmUserForm
    Set frm = New frmUserForm

    The problem is that this new instance of the form does not have the same methods and properties as the form I created within the VBE. Ther is no Show property or method so I have been unable to get the new instance of the form to appear.

    Thanks

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Class and Userforms (2000 SR1)

    Hi,
    Without knowing the specifics of your add-in it's a little hard to know what you need, but I would have generally thought that the easiest way of doing something like this would be to have your addin run a simple frmYourUserformName.Show line and then have a command button on your userform that creates an instance of your class and assigns the relevant control values to the various properties of your class - e.g.
    clsWhatever.Path = me!txtPath
    clsWhatever.FileName = Me!txtFilename
    clsWhatever.ReadData
    Does that help?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Class and Userforms (2000 SR1)

    You are right! I was looking at it from the opposite direction. So what you are saying is to have the UserForm call and use the Class object instead of the Class calling and using the UserForm. That would definately resolve this problem. However, how would you handle a similiar scenario where a Class uses several UserForms?

    Thanks Again!
    Ed

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Class and Userforms (2000 SR1)

    Hi,
    You would use the frmUserformName.Show syntax as before within the relevant procedure in your class module.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class and Userforms (2000 SR1)

    No, just have the class module display the user form using:

    <pre> frmUserformName.Show
    </pre>

    Legare Coleman

  6. #6
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Class and Userforms (2000 SR1)

    So when displaying a UserForm within a Class you would not create a new instance of the form such as:
    Dim fmrNew as frmUserForm
    Set frmNew = New frmUserForm
    ...And instead do the following:
    frmUserFrom.Show

    Thanks
    Ed

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class and Userforms (2000 SR1)

    That's what I would do.
    Legare Coleman

Posting Permissions

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