Solved

Multiple checkbox operation...

Posted on 2014-03-21
7
270 Views
Last Modified: 2014-03-21
There are chkbox1, chkbox2, chkbox3, etc. doing some operation shown down below.

Question : Is there a way to simplify this code using something like:

= fnUpdateChkeBoxes("chkbox1")
= fnUpdateChkeBoxes("chkbox2")
= fnUpdateChkeBoxes("chkbox3")

That goes on the click events of the respective check boxes to call:

Function fnUpdateChkeBoxes(strChek As String)

       val_chkbox1 = chkbox1      
       val_chkbox2 = chkbox2
       val_chkbox3 = chkbox3

End Function

but ignoring check box in the parameter strChek?

Thank you.

'Simplified version:  
Sub chkbox1_Click()

    If chkbox1 = True Then
       ' val_chkbox1 = chkbox1       '<-- this one ignore
       val_chkbox2 = chkbox2
       val_chkbox3 = chkbox3
      .
      .
  End if

End Sub

Sub chkbox2_Click()

    If chkbox1 = True Then
       'val_chkbox1 = chkbox1       
       'val_chkbox2 = chkbox2    '<-- this one ignore
       val_chkbox3 = chkbox3
      .
      .
  End if

End Sub

Sub chkbox3_Click()

    If chkbox3 = True Then
       'val_chkbox1 = chkbox1       
       val_chkbox2 = chkbox2   
       'val_chkbox3 = chkbox3   '<-- this one ignore
      .
      .
  End if

End Sub

Open in new window

0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39946302
call a sub with a param (1,2 or 3) depending on which box is checked.
e.g.

Sub chkbox1_Click()
   If chkbox1 = True Then testSub  1


sub testSub (chk as long)
if chk = 1 then
      val_chkbox2 = chkbox2
       val_chkbox3 = chkbox3
end if
if chk = 2 then   val_chkbox3 = chkbox3
if chk = 3 then   val_chkbox2 = chkbox2
end sub
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 39946320
re> call a sub with a param (1,2 or 3) depending on which box is checked

There are no 1, 2, 3s to call. I have to have full name of the check box. Checkbox1, 2, 3 are used just for illustration.

Also, if I have 30 check boxes, then I have to have 30 if statements. I want to simplify if possible.

Thanks,

Mike
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39946339
try using

me.activecontrol.name
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39946342
if you want to process an event (chkbox click) you will need to call the function from the event.

e.g.
Sub chkbox1_Click()
   If chkbox1 = True Then testSub  1
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39946356
try using

me.activecontrol.name  

or

screen.activecontrol.name

or just
screen.activecontrol

depending on how you call it in the sub/function
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39946523
I wonder why you have 30 checkboxes.  Perhaps you should consider normalizing the schema.

Having a single sub to process 30 checkboxes isn't simplification.  You would need a huge case statement to sort out the source of the click and do what ever is required for that particular checkbox.

If you're going to stick with the 30 options, perhaps a multi-select list box would be simpler to program.  There the user could simulate clicks by selecting various rows.  Your code could loop through the selections and process them but again, if you are doing something different for each checkbox, you should have a separate procedure.  

The Switchboard form (circa 2003) does something like this but in that case they have 8 buttons any one of which could perform about 10 functions with various arguments.   The way the switchboard form works, you don't care what button was pressed.  You only care which of the 10 options that button is supposed to perform.  Your description sounds like you have 30 buttons doing 30 things.  There is no logical way to group them.  It would be simpler to just let them do their own thing.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 39946559
Rey Obrero,

I like me.activecontrol.name, etc. solution.
Function fnUpdateChkeBoxes(strChek As String)

       If me.activecontrol.name <> "chkbox1" Then val_chkbox1 = chkbox1      
       If me.activecontrol.name <> "chkbox2" Then val_chkbox2 = chkbox2
       If me.activecontrol.name <> "chkbox3" Then val_chkbox3 = chkbox3

End Function

Open in new window


I tried and it works,


PatHartman,
I am very picky in making sure tables are normalized. However, these check boxes are used for conditional formatting purpose etc. and also I have limited freedom to do what I want in this project.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question