+ Reply to Thread
Results 1 to 4 of 4

Strange: "For Each Ctrl In UserForm1.Controls" does not work

  1. #1
    Registered User
    Join Date
    03-31-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Strange: "For Each Ctrl In UserForm1.Controls" does not work

    Hi all,

    I have encountered the following weird situation. The following codes run well in the IDE (when we click the Green Play button). But the codes won't execute when actually using the excel file - after open the file, click the the "START" button, then a userform will be shown. There are few textboxes, enter anything into the textbox, then click the commandbutton at the bottom suppose will set all the textbox to null (as it did in the IDE). But it won't work here.

    I attached a copy of the file to ease you to look at the problem.
    Download it from my dropbox: http://dl.dropbox.com/u/68179510/Sample%201.xls
    The following codes is part of the codes in the UserForm1
    Sub ButtonReset_Click()

    Dim Ctrl As Control
    For Each Ctrl In UserForm1.Controls
    If TypeName(Ctrl) = "TextBox" Then
    Ctrl.Value = vbNullString
    End If
    Next Ctrl

    End Sub
    Thank you very much for all the attention and helps
    Attached Files Attached Files

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Strange: "For Each Ctrl In UserForm1.Controls" does not work

    cross post, here

    http://www.mrexcel.com/forum/newrepl...te=1&p=3101577
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    03-31-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Strange: "For Each Ctrl In UserForm1.Controls" does not work

    I'm deeply apologize if cross-posting is not allowed in this forum.
    Kindly please remove this thread.
    Thanks for your reminder, moderator.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Strange: "For Each Ctrl In UserForm1.Controls" does not work

    Xenova

    Cross posting is not allowed in most forums, at least without a a link back to the other posts. Carry on with cross posting & you will find that you will get fewer answers, simply because most advisors use multiple forums.

    If you had actually bothered to read the Forum Rules here then you would have known & also used Code Tags. You agreed to the rules when you joined & it seems a small price for free help.

    For what it's worth, your example with the code works!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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