Solved

Multiple checkbox operation...

Posted on 2014-03-21
7
265 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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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 36

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

828 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