Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

I have a large form with 28 checkboxes on it. The checkboxes are named Qxxxx
where xxxx is a meaningful number that links me to the proper text box also
on the form. (textboxes are named Sxxxx). xxxx is a unique identifier and
not sequential.

I want to disable/enable the appropriate textbox if the corresponding
checkbox is clicked.

I'd prefer to not have to write 28 Qxxxx_Click routines with the exact same
code in all of them. Is there some way to create a generic checkbox_Click
event that can be handled by one routine? Or is there some way to write one
routine and have it handle all the checkbox_Click events?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default generic checkbox click form event handler?

Each check box must have a unique function. But all of the routines can have
one instruction which call a common function.

"fedude" wrote:

I have a large form with 28 checkboxes on it. The checkboxes are named Qxxxx
where xxxx is a meaningful number that links me to the proper text box also
on the form. (textboxes are named Sxxxx). xxxx is a unique identifier and
not sequential.

I want to disable/enable the appropriate textbox if the corresponding
checkbox is clicked.

I'd prefer to not have to write 28 Qxxxx_Click routines with the exact same
code in all of them. Is there some way to create a generic checkbox_Click
event that can be handled by one routine? Or is there some way to write one
routine and have it handle all the checkbox_Click events?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

Joel,

Is there a generic form change event that I can catch in a routine that then
loops through the checkbox controls to see if they've changed?

"Joel" wrote:

Each check box must have a unique function. But all of the routines can have
one instruction which call a common function.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

Here is the routine I'm writing for each of the checkboxes. I'm unsure how
to genericize this so I can create control names from the name of the
checkbox.


Suggestions?
-----------------------------------------------

Private Sub Q1062_Click()
Dim player As Integer

'capture the unique number
player = Right(S1062.Name, 4)

S1062.Value = ""
If Q1062.Value = True Then
L1062.Tag = L1062.Caption
L1062.Caption = "Substitute"
S1062.Enabled = False
S1062.BackColor = &H8000000B
Else
L1062.Caption = L1062.Tag
S1062.Enabled = True
S1062.BackColor = &H80000005
End If
End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default generic checkbox click form event handler?

These are the events


AddinInstall

AddinUninstall

BeforeClose

BeforePrint

BeforeSave

Deactivate

NewSheet

Open

PivotTableCloseConnection

PivotTableOpenConnection

SheetActivate

SheetBeforeDoubleClick

SheetBeforeRightClick

SheetCalculate

SheetChange

SheetDeactivate

SheetFollowHyperlink

SheetPivotTableUpdate

SheetSelectionChange

WindowActivate

WindowDeactivate

WindowResize


activeworkbook

"fedude" wrote:

Joel,

Is there a generic form change event that I can catch in a routine that then
loops through the checkbox controls to see if they've changed?

"Joel" wrote:

Each check box must have a unique function. But all of the routines can have
one instruction which call a common function.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default generic checkbox click form event handler?

Add a class module named Class1 (later name as say clsCBxEvnts)

' code in Class1
' add other events, select cbx from the middle dropdown
' then other events from the right dropdown

Public WithEvents cbx As MSForms.CheckBox
Public tbx As MSForms.TextBox

Private Sub cbx_Change()
tbx.Enabled = cbx.Value
End Sub

''Userform code

' two checkboxes named CheckBox1 & 2
' two textboxes named TextBox1 & 2

Dim arrClsCBoxEvnts(1 To 2) As Class1 ' or say clsCBxEvnts

Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To 2
Set arrClsCBoxEvnts(i) = New Class1
With arrClsCBoxEvnts(i)
Set .cbx = Me.Controls("CheckBox" & i)
Set .tbx = Me.Controls("TextBox" & i)
.tbx.Enabled = .cbx.Value
End With
Next
End Sub

Regards,
Peter T

"fedude" wrote in message
...
Joel,

Is there a generic form change event that I can catch in a routine that

then
loops through the checkbox controls to see if they've changed?

"Joel" wrote:

Each check box must have a unique function. But all of the routines can

have
one instruction which call a common function.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default generic checkbox click form event handler?

John Walkenbach shows a way:
http://j-walk.com/ss/excel/tips/tip44.htm

His code actually uses commandbuttons, but it can be modified to use Checkboxes.

In the class module:
Option Explicit
Public WithEvents CBXGroup As MSForms.CheckBox
Private Sub CBXGroup_Click()
MsgBox "Hello from " & CBXGroup.Name & vbLf & CBXGroup.Value
End Sub

In a General module:

Option Explicit
Dim myCBXes() As New Class1
Sub ShowDialog()
Dim CBXCount As Long
Dim ctl As Control

CBXCount = 0
For Each ctl In UserForm1.Controls
If TypeOf ctl Is MSForms.CheckBox Then
CBXCount = CBXCount + 1
ReDim Preserve myCBXes(1 To CBXCount)
Set myCBXes(CBXCount).CBXGroup = ctl
End If
Next ctl
UserForm1.Show
End Sub

Make sure you read John's instructions.
fedude wrote:

I have a large form with 28 checkboxes on it. The checkboxes are named Qxxxx
where xxxx is a meaningful number that links me to the proper text box also
on the form. (textboxes are named Sxxxx). xxxx is a unique identifier and
not sequential.

I want to disable/enable the appropriate textbox if the corresponding
checkbox is clicked.

I'd prefer to not have to write 28 Qxxxx_Click routines with the exact same
code in all of them. Is there some way to create a generic checkbox_Click
event that can be handled by one routine? Or is there some way to write one
routine and have it handle all the checkbox_Click events?


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default generic checkbox click form event handler?

You need to use oleobjects like the code below. The oleobject doesn't have
the name of the box but it does have the caption. You need to do the same
thing with the other objects.


Private Sub Q1062_Click()
call common_click("1062")
end sub

common_click(box_num as string)

Dim player As Integer
set box = oleobject("Q" & box_num).object
'capture the unique number
player = Right(box.Name, 4)

box.Value = ""
If box.Value = True Then
L1062.Tag = L1062.Caption
L1062.Caption = "Substitute"
S1062.Enabled = False
S1062.BackColor = &H8000000B
Else
L1062.Caption = L1062.Tag
S1062.Enabled = True
S1062.BackColor = &H80000005
End If
End Sub


"fedude" wrote:

Here is the routine I'm writing for each of the checkboxes. I'm unsure how
to genericize this so I can create control names from the name of the
checkbox.


Suggestions?
-----------------------------------------------

Private Sub Q1062_Click()
Dim player As Integer

'capture the unique number
player = Right(S1062.Name, 4)

S1062.Value = ""
If Q1062.Value = True Then
L1062.Tag = L1062.Caption
L1062.Caption = "Substitute"
S1062.Enabled = False
S1062.BackColor = &H8000000B
Else
L1062.Caption = L1062.Tag
S1062.Enabled = True
S1062.BackColor = &H80000005
End If
End Sub

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default generic checkbox click form event handler?

If you have a userform then add the group box around all the checkboxes. If
your form is a worksheet then add the group box from the toolbar "Forms" (add
from view menu if it is not one of your normal forms).
"Dave Peterson" wrote:

John Walkenbach shows a way:
http://j-walk.com/ss/excel/tips/tip44.htm

His code actually uses commandbuttons, but it can be modified to use Checkboxes.

In the class module:
Option Explicit
Public WithEvents CBXGroup As MSForms.CheckBox
Private Sub CBXGroup_Click()
MsgBox "Hello from " & CBXGroup.Name & vbLf & CBXGroup.Value
End Sub

In a General module:

Option Explicit
Dim myCBXes() As New Class1
Sub ShowDialog()
Dim CBXCount As Long
Dim ctl As Control

CBXCount = 0
For Each ctl In UserForm1.Controls
If TypeOf ctl Is MSForms.CheckBox Then
CBXCount = CBXCount + 1
ReDim Preserve myCBXes(1 To CBXCount)
Set myCBXes(CBXCount).CBXGroup = ctl
End If
Next ctl
UserForm1.Show
End Sub

Make sure you read John's instructions.
fedude wrote:

I have a large form with 28 checkboxes on it. The checkboxes are named Qxxxx
where xxxx is a meaningful number that links me to the proper text box also
on the form. (textboxes are named Sxxxx). xxxx is a unique identifier and
not sequential.

I want to disable/enable the appropriate textbox if the corresponding
checkbox is clicked.

I'd prefer to not have to write 28 Qxxxx_Click routines with the exact same
code in all of them. Is there some way to create a generic checkbox_Click
event that can be handled by one routine? Or is there some way to write one
routine and have it handle all the checkbox_Click events?


--

Dave Peterson

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

Peter, you're my new hero. THANKS!!



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

Dave,

Took a while for me to customize it for my checkboxes, but this works great.
Thanks!!!

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default generic checkbox click form event handler?

Unfortunately, all the checkboxes are not located in a separate area of the
form. They are interspersed with text boxes.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Click event... John Keith[_2_] Excel Programming 1 June 19th 07 05:40 PM
Click event for checkbox from Forms toolbar Carolyn Excel Discussion (Misc queries) 6 September 11th 06 08:16 PM
Passing CheckBox Value from Click Event to Main Macro ExcelMonkey[_190_] Excel Programming 2 February 1st 05 05:47 PM
Click Checkbox Event Montana DOJ Help Desk Excel Programming 4 November 11th 04 04:25 AM
Assigning click event to OleObjects checkbox Jim McLeod Excel Programming 5 April 20th 04 07:02 PM


All times are GMT +1. The time now is 09:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"