Code runs more than needed
Code runs more than needed
Code runs more than needed
Code runs more than needed
Code runs more than needed
Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed
Code runs more than needed Code runs more than needed
Code runs more than needed
Go Back  Xtreme Visual Basic Talk > > > > Code runs more than needed


Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2017, 03:41 AM
Visvang's Avatar
Visvang Visvang is offline
Centurion
 
Join Date: Mar 2010
Posts: 119
Question Code runs more than needed


Hi All,

I pulled the following code from the web, and every time it gets to userform1 it kind of starts all over to UserForm_Initialize(), but eventually it finish the code.
I just need all my checkboxes to do the same thing.

Code:
Private Sub SomeCheckBox_Click()

        'Do stuff with Checkboxes
    
End Sub
Private Sub PrepCheckBoxes()

    Dim oneControl As MSForms.Control
    Dim newAllBox As UsrFrmRateSong
    
    Set AllCheckBoxes = New Collection
    
    For Each oneControl In Me.Controls
        If TypeName(oneControl) = "CheckBox" Then
            Set newAllBox = New Userform1
            Set newAllBox.SomeCheckBox = oneControl
            AllCheckBoxes.Add Item:=newAllBox
    
            Set SomeCheckBox = oneControl: Call SomeCheckBox_Click
        End If
    Next oneControl
    
    Set SomeCheckBox = Nothing
    Set newAllBox = Nothing
     
End Sub
Private Sub UserForm_Initialize()

    Dim oneForm As Object, meCount As Lon
    
    For Each oneForm In UserForms
        meCount = meCount - CLng(oneForm.Name = Me.Name)
    Next oneForm
    If meCount <= 1 Then
        Call PrepCheckBoxes
    End If
    
End Sub
Is there a better way of doing this?
__________________
Whether you believe you can do a thing or not, you are right - Henry Ford

Record a macro if your not sure how things work!
Reply With Quote
  #2  
Old 04-10-2017, 08:50 AM
MPiCode runs more than needed MPi is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Dec 2001
Location: Quebec
Posts: 1,000
Default

Hi,

Can you explain what you need to do exactly ?
__________________
MPi²
Reply With Quote
Reply

Tags
set, onecontrol, mecount, newallbox, dim, code, private, oneform, somecheckbox, checkboxes, somecheckbox_click, userform_initialize, userform1, item=newallbox, newallbox.somecheckbox, allcheckboxes.add, checkbox, pulled, me.controls, typenameonecontrol, call, userforms, clngoneform.name, me.name, lon


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Code runs more than needed
Code runs more than needed
Code runs more than needed Code runs more than needed
Code runs more than needed
Code runs more than needed
Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed Code runs more than needed
Code runs more than needed
Code runs more than needed
 
Code runs more than needed
Code runs more than needed
 
-->