Displaying Another UserForm when click on CheckBox in UserForm 
Author Message
 Displaying Another UserForm when click on CheckBox in UserForm

I cannot seem to get another userform to load when the user clicks on one of
the checkboxes created from the code below.  I have tried several options
and have two of them pasted at the bottom of this message.  I have also
tried the http://www.*-*-*.com/
site.  That does not seem to work either.  Please let me know what I am
doing wrong.  Any help is greatly appreciated!  And as always thanks in
advance.

Option Explicit
Dim WS As Worksheet
Dim rw As Integer
Dim x As MSForms.Control

Private Sub CommandButton1_Click()
Me.Hide
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim i As Integer
i = 1
Set WS = Worksheets("Candidates")
    With WS
        rw = 2
            Do While .Cells(rw, 1) <> ""
                Set x = Me.Controls.Add("Forms.CheckBox.1")
                x.Caption = .Cells(rw, 2)
                .Cells(rw, 13) = False
                x.ControlSource = "candidates!M" & rw
                x.Top = 18 * rw
                x.Left = 8
                rw = rw + 1
            Loop
    End With
  End Sub

Here is where my problem occurs.  This code is just ignored.  What I am
trying to accomplish is displaying another userform when the user clicks on
one of the checkboxes created from the above code.
Private Sub x_Click()

Dim cntrl As MSForms.Control
Dim i As Integer
i = 1
For Each x In FCandidates.Controls
  If TypeOf x Is MSForms.CheckBox Then
    If x.Value = True Then
     Load FCanChoice
     FCanChoice.Show
     i = i + 1
    End If
  End If
Next
End Sub

Here is another one of my examples that I have tried.
Private Sub x_Click()
If x = True Then
Load FCanChoice
FCanChoice.Show
Else
'Do Nothing
End If
End Sub

Thanks again,
Cynthia G.



Mon, 25 Apr 2005 13:12:01 GMT  
 Displaying Another UserForm when click on CheckBox in UserForm
Cynthia

Here's an example to get you started.  It uses the technique from John's
website.  First, create a class module with this in it

Public WithEvents ChBoxGrp As MSForms.CheckBox

Private Sub ChBoxGrp_Click()
    UserForm2.Show
End Sub

Then in the initialize event of your userform, put this.  Notice that as I'm
adding controls to the userform, I'm also adding them to the class so that
the Click event defined in the class will run when any of them is clicked.
I also used a For-Each loop instead of a Do Loop.  You can still use the Do
Loop, I didn't because I prefer the For Each.

Option Explicit

Dim ChBoxes() As New Class1

Private Sub UserForm_Initialize()

Dim BoxCount As Long
Dim ws As Worksheet
Dim cell As Range
Dim ctl As Control

Set ws = ThisWorkbook.Sheets("Candidates")

For Each cell In ws.Range("A1", ws.Range("a1").End(xlDown))
    Set ctl = Me.Controls.Add("Forms.CheckBox.1")
    With ctl
        .Caption = cell.Offset(0, 1).Value
        cell.Offset(0, 12).Value = False
        .ControlSource = ws.Name & "!" & _
            cell.Offset(0, 12).Address
        .Top = 18 * cell.Row
        .Left = 8

        'Add the control to the class
        BoxCount = BoxCount + 1
        ReDim Preserve ChBoxes(1 To BoxCount)
        Set ChBoxes(BoxCount).ChBoxGrp = ctl
    End With
Next cell

End Sub

--
{*filter*} Kusleika
MVP - Excel

Post all replies to the newsgroup.


Quote:
> I cannot seem to get another userform to load when the user clicks on one
of
> the checkboxes created from the code below.  I have tried several options
> and have two of them pasted at the bottom of this message.  I have also
> tried the http://www.*-*-*.com/
web
> site.  That does not seem to work either.  Please let me know what I am
> doing wrong.  Any help is greatly appreciated!  And as always thanks in
> advance.

> Option Explicit
> Dim WS As Worksheet
> Dim rw As Integer
> Dim x As MSForms.Control

> Private Sub CommandButton1_Click()
> Me.Hide
> Unload Me
> End Sub

> Private Sub UserForm_Initialize()
> Dim i As Integer
> i = 1
> Set WS = Worksheets("Candidates")
>     With WS
>         rw = 2
>             Do While .Cells(rw, 1) <> ""
>                 Set x = Me.Controls.Add("Forms.CheckBox.1")
>                 x.Caption = .Cells(rw, 2)
>                 .Cells(rw, 13) = False
>                 x.ControlSource = "candidates!M" & rw
>                 x.Top = 18 * rw
>                 x.Left = 8
>                 rw = rw + 1
>             Loop
>     End With
>   End Sub

> Here is where my problem occurs.  This code is just ignored.  What I am
> trying to accomplish is displaying another userform when the user clicks
on
> one of the checkboxes created from the above code.
> Private Sub x_Click()

> Dim cntrl As MSForms.Control
> Dim i As Integer
> i = 1
> For Each x In FCandidates.Controls
>   If TypeOf x Is MSForms.CheckBox Then
>     If x.Value = True Then
>      Load FCanChoice
>      FCanChoice.Show
>      i = i + 1
>     End If
>   End If
> Next
> End Sub

> Here is another one of my examples that I have tried.
> Private Sub x_Click()
> If x = True Then
> Load FCanChoice
> FCanChoice.Show
> Else
> 'Do Nothing
> End If
> End Sub

> Thanks again,
> Cynthia G.



Tue, 26 Apr 2005 02:52:10 GMT  
 Displaying Another UserForm when click on CheckBox in UserForm
Cynthia, in your  code:

Quote:
> Dim cntrl As MSForms.Control
> Dim i As Integer
> i = 1
> For Each x In FCandidates.Controls
>   If TypeOf x Is MSForms.CheckBox Then

.... you DIM'd cntrl as Control but didn't use it.

For Each cntrl In FCandidates.Controls
   If TypeOf cntrl Is MSForms.CheckBox Then
     If cntrl.Value = True Then

I'f recommend that you add
OPTION EXPLICIT
as the first line of a module.

Patrick Molloy
Microsoft Excel MVP


Quote:
> I cannot seem to get another userform to load when the user clicks on one
of
> the checkboxes created from the code below.  I have tried several options
> and have two of them pasted at the bottom of this message.  I have also
> tried the http://j-walk.com/ss/excel/tips/tip44.htm from John Walkenbach
web
> site.  That does not seem to work either.  Please let me know what I am
> doing wrong.  Any help is greatly appreciated!  And as always thanks in
> advance.

> Option Explicit
> Dim WS As Worksheet
> Dim rw As Integer
> Dim x As MSForms.Control

> Private Sub CommandButton1_Click()
> Me.Hide
> Unload Me
> End Sub

> Private Sub UserForm_Initialize()
> Dim i As Integer
> i = 1
> Set WS = Worksheets("Candidates")
>     With WS
>         rw = 2
>             Do While .Cells(rw, 1) <> ""
>                 Set x = Me.Controls.Add("Forms.CheckBox.1")
>                 x.Caption = .Cells(rw, 2)
>                 .Cells(rw, 13) = False
>                 x.ControlSource = "candidates!M" & rw
>                 x.Top = 18 * rw
>                 x.Left = 8
>                 rw = rw + 1
>             Loop
>     End With
>   End Sub

> Here is where my problem occurs.  This code is just ignored.  What I am
> trying to accomplish is displaying another userform when the user clicks
on
> one of the checkboxes created from the above code.
> Private Sub x_Click()

> Dim cntrl As MSForms.Control
> Dim i As Integer
> i = 1
> For Each x In FCandidates.Controls
>   If TypeOf x Is MSForms.CheckBox Then
>     If x.Value = True Then
>      Load FCanChoice
>      FCanChoice.Show
>      i = i + 1
>     End If
>   End If
> Next
> End Sub

> Here is another one of my examples that I have tried.
> Private Sub x_Click()
> If x = True Then
> Load FCanChoice
> FCanChoice.Show
> Else
> 'Do Nothing
> End If
> End Sub

> Thanks again,
> Cynthia G.



Tue, 26 Apr 2005 03:07:52 GMT  
 Displaying Another UserForm when click on CheckBox in UserForm
What can I say other than WOW!  Thank you again!!

You have come to my rescue time and time again and I greatly appreciate it.
Your code works perfectly and now I understand better about classmodules.
Thanks for taking the time to understand my problem and not only helping me
with the code, but explaining it as you went.

Thanks again,
Cynthia G.

PS.  I will try and leave you alone for awhile now, however, no promises.
:)


Quote:
> Cynthia

> Here's an example to get you started.  It uses the technique from John's
> website.  First, create a class module with this in it

> Public WithEvents ChBoxGrp As MSForms.CheckBox

> Private Sub ChBoxGrp_Click()
>     UserForm2.Show
> End Sub

> Then in the initialize event of your userform, put this.  Notice that as
I'm
> adding controls to the userform, I'm also adding them to the class so that
> the Click event defined in the class will run when any of them is clicked.
> I also used a For-Each loop instead of a Do Loop.  You can still use the
Do
> Loop, I didn't because I prefer the For Each.

> Option Explicit

> Dim ChBoxes() As New Class1

> Private Sub UserForm_Initialize()

> Dim BoxCount As Long
> Dim ws As Worksheet
> Dim cell As Range
> Dim ctl As Control

> Set ws = ThisWorkbook.Sheets("Candidates")

> For Each cell In ws.Range("A1", ws.Range("a1").End(xlDown))
>     Set ctl = Me.Controls.Add("Forms.CheckBox.1")
>     With ctl
>         .Caption = cell.Offset(0, 1).Value
>         cell.Offset(0, 12).Value = False
>         .ControlSource = ws.Name & "!" & _
>             cell.Offset(0, 12).Address
>         .Top = 18 * cell.Row
>         .Left = 8

>         'Add the control to the class
>         BoxCount = BoxCount + 1
>         ReDim Preserve ChBoxes(1 To BoxCount)
>         Set ChBoxes(BoxCount).ChBoxGrp = ctl
>     End With
> Next cell

> End Sub

> --
>{*filter*} Kusleika
> MVP - Excel

> Post all replies to the newsgroup.



> > I cannot seem to get another userform to load when the user clicks on
one
> of
> > the checkboxes created from the code below.  I have tried several
options
> > and have two of them pasted at the bottom of this message.  I have also
> > tried the http://www.*-*-*.com/
> web
> > site.  That does not seem to work either.  Please let me know what I am
> > doing wrong.  Any help is greatly appreciated!  And as always thanks in
> > advance.

> > Option Explicit
> > Dim WS As Worksheet
> > Dim rw As Integer
> > Dim x As MSForms.Control

> > Private Sub CommandButton1_Click()
> > Me.Hide
> > Unload Me
> > End Sub

> > Private Sub UserForm_Initialize()
> > Dim i As Integer
> > i = 1
> > Set WS = Worksheets("Candidates")
> >     With WS
> >         rw = 2
> >             Do While .Cells(rw, 1) <> ""
> >                 Set x = Me.Controls.Add("Forms.CheckBox.1")
> >                 x.Caption = .Cells(rw, 2)
> >                 .Cells(rw, 13) = False
> >                 x.ControlSource = "candidates!M" & rw
> >                 x.Top = 18 * rw
> >                 x.Left = 8
> >                 rw = rw + 1
> >             Loop
> >     End With
> >   End Sub

> > Here is where my problem occurs.  This code is just ignored.  What I am
> > trying to accomplish is displaying another userform when the user clicks
> on
> > one of the checkboxes created from the above code.
> > Private Sub x_Click()

> > Dim cntrl As MSForms.Control
> > Dim i As Integer
> > i = 1
> > For Each x In FCandidates.Controls
> >   If TypeOf x Is MSForms.CheckBox Then
> >     If x.Value = True Then
> >      Load FCanChoice
> >      FCanChoice.Show
> >      i = i + 1
> >     End If
> >   End If
> > Next
> > End Sub

> > Here is another one of my examples that I have tried.
> > Private Sub x_Click()
> > If x = True Then
> > Load FCanChoice
> > FCanChoice.Show
> > Else
> > 'Do Nothing
> > End If
> > End Sub

> > Thanks again,
> > Cynthia G.



Tue, 26 Apr 2005 04:03:32 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using mouse-click outside userform to close userform

2. UserForm Checkbox link to Checkbox in document

3. UserForm To UserForm

4. Variable(s) Reset by Showing 2nd UserForm on top 1st UserForm

5. Passing a Variable from one Userform to another Userform

6. Userform Properties not available in MSForms.Userform

7. VBProject / VBComponent [DYNAMIC Userform called from a STATIC Userform]

8. UserForm or not to UserForm?

9. UserForm events and moving a UserForm

10. Opening userforms from other userforms


 
Powered by phpBB® Forum Software © phpBB Group