ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing reference to a checkbox to a subroutine. (https://www.excelbanter.com/excel-programming/407430-passing-reference-checkbox-subroutine.html)

MikeAllgood

Passing reference to a checkbox to a subroutine.
 
I have an application where I am trying to enable/disable the controls in a
frame on a UserForm in VBA Office 2003. I have a checkbox in the frame and
when the checkbox is clicked, based on its value, I want to call one of two
subroutines. The subroutines have two arguments: the frame and the checkbox.
Whenever I try to run this code I get a type mismatch error. I know the
default property of the checkbox is the value property. Is it possible that
when I call the subs and reference the checkbox that it is trying to send a
boolean reference instead of a reference to the actual checkbox control? If
that is the case how do I get around this? If that isn't the problem, what
is, and how do I get it to work? The code is below. Thanks.

CheckBox clicked event:
Private Sub ckbTalentMod1_Click()
If ckbTalentMod1.Value = True Then
Call EnableObjects(fraTalentMod1, ckbTalentMod1)
Else
Call DisableObjects(fraTalentMod1, ckbTalentMod1)
End If
End Sub

Subroutine to enable the controls in the frame:


MikeAllgood

Passing reference to a checkbox to a subroutine.
 
Sorry, I forgot to paste the subroutine. Here it is.

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label" And
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


Again, thanks.

"MikeAllgood" wrote:

I have an application where I am trying to enable/disable the controls in a
frame on a UserForm in VBA Office 2003. I have a checkbox in the frame and
when the checkbox is clicked, based on its value, I want to call one of two
subroutines. The subroutines have two arguments: the frame and the checkbox.
Whenever I try to run this code I get a type mismatch error. I know the
default property of the checkbox is the value property. Is it possible that
when I call the subs and reference the checkbox that it is trying to send a
boolean reference instead of a reference to the actual checkbox control? If
that is the case how do I get around this? If that isn't the problem, what
is, and how do I get it to work? The code is below. Thanks.

CheckBox clicked event:
Private Sub ckbTalentMod1_Click()
If ckbTalentMod1.Value = True Then
Call EnableObjects(fraTalentMod1, ckbTalentMod1)
Else
Call DisableObjects(fraTalentMod1, ckbTalentMod1)
End If
End Sub

Subroutine to enable the controls in the frame:


Bob Phillips

Passing reference to a checkbox to a subroutine.
 
Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
msforms.CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And _
TypeName(cCtl) < "Label" And _
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"MikeAllgood" wrote in message
...
Sorry, I forgot to paste the subroutine. Here it is.

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label" And
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


Again, thanks.

"MikeAllgood" wrote:

I have an application where I am trying to enable/disable the controls in
a
frame on a UserForm in VBA Office 2003. I have a checkbox in the frame
and
when the checkbox is clicked, based on its value, I want to call one of
two
subroutines. The subroutines have two arguments: the frame and the
checkbox.
Whenever I try to run this code I get a type mismatch error. I know the
default property of the checkbox is the value property. Is it possible
that
when I call the subs and reference the checkbox that it is trying to send
a
boolean reference instead of a reference to the actual checkbox control?
If
that is the case how do I get around this? If that isn't the problem,
what
is, and how do I get it to work? The code is below. Thanks.

CheckBox clicked event:
Private Sub ckbTalentMod1_Click()
If ckbTalentMod1.Value = True Then
Call EnableObjects(fraTalentMod1, ckbTalentMod1)
Else
Call DisableObjects(fraTalentMod1, ckbTalentMod1)
End If
End Sub

Subroutine to enable the controls in the frame:




MikeAllgood

Passing reference to a checkbox to a subroutine.
 
Now what happens is the subroutine is getting called but when it get to the
line:

cCtl.enable = True

I get a "Object doesn't support this property or method" error (Error 438).
Why would a control object not have an enable property? What am I doing wrong?

Thanks,
Mike

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As _
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label" And _
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True <---Error happens here!
End If
Next cCtl
End Sub


"Bob Phillips" wrote:

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
msforms.CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And _
TypeName(cCtl) < "Label" And _
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"MikeAllgood" wrote in message
...
Sorry, I forgot to paste the subroutine. Here it is.

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label" And
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


Again, thanks.

"MikeAllgood" wrote:

I have an application where I am trying to enable/disable the controls in
a
frame on a UserForm in VBA Office 2003. I have a checkbox in the frame
and
when the checkbox is clicked, based on its value, I want to call one of
two
subroutines. The subroutines have two arguments: the frame and the
checkbox.
Whenever I try to run this code I get a type mismatch error. I know the
default property of the checkbox is the value property. Is it possible
that
when I call the subs and reference the checkbox that it is trying to send
a
boolean reference instead of a reference to the actual checkbox control?
If
that is the case how do I get around this? If that isn't the problem,
what
is, and how do I get it to work? The code is below. Thanks.

CheckBox clicked event:
Private Sub ckbTalentMod1_Click()
If ckbTalentMod1.Value = True Then
Call EnableObjects(fraTalentMod1, ckbTalentMod1)
Else
Call DisableObjects(fraTalentMod1, ckbTalentMod1)
End If
End Sub

Subroutine to enable the controls in the frame:





Tim Zych

Passing reference to a checkbox to a subroutine.
 
Enabled, not Enable

--
Tim Zych
SF, CA

"MikeAllgood" wrote in message
...
Now what happens is the subroutine is getting called but when it get to
the
line:

cCtl.enable = True

I get a "Object doesn't support this property or method" error (Error
438).
Why would a control object not have an enable property? What am I doing
wrong?

Thanks,
Mike

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As _
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label" And _
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True <---Error happens here!
End If
Next cCtl
End Sub


"Bob Phillips" wrote:

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
msforms.CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And _
TypeName(cCtl) < "Label" And _
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"MikeAllgood" wrote in message
...
Sorry, I forgot to paste the subroutine. Here it is.

Public Sub EnableObjects(ByRef fraEnable As Frame, ByRef myCheckBox As
CheckBox)
Dim cCtl As Control

For Each cCtl In fraEnable.Controls
If cCtl.Name < myCheckBox.Name And TypeName(cCtl) < "Label"
And
cCtl.Name < "txtTalentMod1Total" Then
cCtl.enable = True
End If
Next cCtl
End Sub


Again, thanks.

"MikeAllgood" wrote:

I have an application where I am trying to enable/disable the controls
in
a
frame on a UserForm in VBA Office 2003. I have a checkbox in the frame
and
when the checkbox is clicked, based on its value, I want to call one
of
two
subroutines. The subroutines have two arguments: the frame and the
checkbox.
Whenever I try to run this code I get a type mismatch error. I know
the
default property of the checkbox is the value property. Is it possible
that
when I call the subs and reference the checkbox that it is trying to
send
a
boolean reference instead of a reference to the actual checkbox
control?
If
that is the case how do I get around this? If that isn't the problem,
what
is, and how do I get it to work? The code is below. Thanks.

CheckBox clicked event:
Private Sub ckbTalentMod1_Click()
If ckbTalentMod1.Value = True Then
Call EnableObjects(fraTalentMod1, ckbTalentMod1)
Else
Call DisableObjects(fraTalentMod1, ckbTalentMod1)
End If
End Sub

Subroutine to enable the controls in the frame:








All times are GMT +1. The time now is 04:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com