Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiple checkbox operation...

Posted on 2014-03-21
7
Medium Priority
?
272 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
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
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 2000 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 39

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

705 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