+ Reply to Thread
Results 1 to 4 of 4

MSForms.CommandButton problem

  1. #1
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    MSForms.CommandButton problem

    Hi!

    I've worked a solution for my problem but I would like to understand why this happens.

    I have a form with 2 buttons and a frame. Inside the frame I have another button. I get a Type Error Message when I run the code and I don't understand why.

    Here is my code
    Please Login or Register  to view this content.
    I've worked a solution using the following code (I saw this in another thread).

    Please Login or Register  to view this content.
    Can anybody enlighten me?

    Thank you!
    Last edited by pmguerra; 01-29-2009 at 11:04 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: MSForms.CommandButton problem

    The controls collection returns many different control types depending what is on the userform.

    You defined the loops index object as being speficially a CommandButton, so when the first control that is not a command button is returned an error would be raised. The for each loop is not clever enough to return only commandbuttons.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: MSForms.CommandButton problem

    It is a bit strange since it is declared as a commandbutton...

    I'm assuming that the alternative code I've used is the correct one.

    Thank you for your reply!

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: MSForms.CommandButton problem

    Declaring it explicity as a commandbutton is the problem.

    When it loops through ALL of the controls those that are not commandbuttons will cause the loop to fail.

    The second way is how to do it. Loop with a Control index variable and test for control type to perfrom tasks on properties that may only apply to that control type.

+ 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