Question Case statement with multiple option groups (1 Viewer)

Jediknight

New member
Local time
Yesterday, 21:18
Joined
Jul 11, 2019
Messages
15
Hello,
I’m currently putting together on a form 2 option groups with 5 options each.

The result of the selection of the radio buttons produce a statement in a text box. A radio button have to be selected in each of the option group.
Therefore there is 25 possible statements.

I’ve associated a value from 1 to 5 for option group 1 and from 6 to 10 for option group 2.

Here is what I have for now.

Private Sub Form_AfterUpdate()

Select Case True

Case 1
OptionGroup1 = 1 And OptionGroup2 = 6
Textbox = “Result for option 1 and 6 selected”

Case 2
OptionGroup1 = 1 And OptionGroup2 = 7
Textbox = “Result for option 1 and 7 selected”

.
.
.
.

End select
End sub

The problem is that nothing shows up in the Textbox !?
Note : I dont mind doing the 25 cases :/ the problem is that I cant even make it work with 2 cases :(

Thank you for the assistance.
Best regards.



Sent from my iPhone using Tapatalk
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:18
Joined
Oct 29, 2018
Messages
21,358
Hi. I think maybe because Case 1 and/or Case 2 is probably not evaluating as you expected. You might try it this way instead:
Code:
Select Case True
    Case OptionGroup1=1 And OptionGroup2=6
        Textbox = "Result for option 1 and 6 are selected."
    Case OptionGroup1=1 And OptionGroup2=7
        Textbox = "Result for option 1 and 7 are selected."
and so on...
End Select
 

Jediknight

New member
Local time
Yesterday, 21:18
Joined
Jul 11, 2019
Messages
15
Thank you for the assistance.
Unfortunately by doing so only the first combination is working and this is only true if I replace :

Private Sub Form_afterUpdate()

By

Private OptionGroup1_Afterupdate()

... but then what about OptionGroup2 ??

Also when I select another button the text in the textbox is not updated with respect to the new selected options.
Thank you for the help.




Sent from my iPhone using Tapatalk
 

June7

AWF VIP
Local time
Yesterday, 17:18
Joined
Mar 9, 2014
Messages
5,423
Have to repeat the code under OptionGroup2. Or have the Select Case code in another procedure that both AfterUpdate events can call.

Have you expanded the code for all 25 conditions? Post your code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:18
Joined
May 7, 2009
Messages
19,169
there are on 5 options on each group.
 

Jediknight

New member
Local time
Yesterday, 21:18
Joined
Jul 11, 2019
Messages
15
Have to repeat the code under OptionGroup2. Or have the Select Case code in another procedure that both AfterUpdate events can call.

Have you expanded the code for all 25 conditions? Post your code.


I know what you are refering to, but I think my struggle is that the the textbox is not refreshing if the user is selecting another option. Textbox is showing only the first selection response. If user changes its options the first response remains in the textbox ...


Sent from my iPhone using Tapatalk
 

Micron

AWF VIP
Local time
Yesterday, 21:18
Joined
Oct 20, 2018
Messages
3,476
I suspect you can do it in one case if you make it about the sum of the values between the groups and if those sums are unique. That is the way the message box function buttons argument works if you use numeric values. In other words, the values used are such that no two sums can produce the same result.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:18
Joined
May 7, 2009
Messages
19,169
Textbox is a reserved word (an object in access). try enclosing it in bracket or better qualify it:

Me![Textbox] = ….
 

June7

AWF VIP
Local time
Yesterday, 17:18
Joined
Mar 9, 2014
Messages
5,423
I tested code using option group AfterUpdate and works for me, even with name Textbox without brackets. If you want to provide db for analysis, follow instructions at bottom of my post.
 
Last edited:

Jediknight

New member
Local time
Yesterday, 21:18
Joined
Jul 11, 2019
Messages
15
As requested, this is the code I'm using. If anybody can help finding the mistake that would be appreicated.

Code:
Option Compare Database
------------------------------------------------------------------------------------
Private Sub OptionGroup1_AfterUpdate()
 
Select Case True
Case OptionGroup1 = 1 And OptionGroup2 = 6
Text224 = "1 and 6"
 
Case OptionGroup1 = 1 And OptionGroup2= 7
Text224 = "1 and 7"
 
Case OptionGroup1 = 1And OptionGroup2= 8
Text224 = "1 and 8"
 
Case OptionGroup1 = 1  And OptionGroup2= 9
Text224 = "1 and 9"
 
Case OptionGroup1 = 1 And OptionGroup2= 10
Text224 = "1 and 10"
 
 
 
Case OptionGroup = 2 And OptionGroup2 = 6
Text224 = "2 and 6"
 
Case OptionGroup1 = 2 And OptionGroup2= 7
Text224 = "2 and 7"
 
Case OptionGroup1 = 2 And OptionGroup2= 8
Text224 = "2 and 8"
 
Case OptionGroup1 = 2 And OptionGroup2= 9
Text224 = "2 and 9"
 
Case OptionGroup1 = 2 And OptionGroup2= 10
Text224 = "2 and 10"
 
Case OptionGroup1 = 2 And OptionGroup2= 7
Text224 = "2 and 7"
 
 
Case OptionGroup = 3 And OptionGroup2 = 6
Text224 = "3 and 6"
 
Case OptionGroup1 = 3 And OptionGroup2= 7
Text224 = "3 and 7"
 
Case OptionGroup1 = 3 And OptionGroup2= 8
 
Text224 = "3 and 8"
 
Case OptionGroup1 = 3 And OptionGroup2= 9
Text224 = "3 and 9"
 
Case OptionGroup1 = 3 And OptionGroup2= 10
Text224 = "3 and 10"
 
 
Case OptionGroup = 4 And OptionGroup2 = 6
Text224 = "4 and 6"
 
Case OptionGroup1 = 4 And OptionGroup2= 7
Text224 = "4 and 7"
 
Case OptionGroup1 = 4 And OptionGroup2= 8
Text224 = "4 and 8"
 
Case OptionGroup1 = 4 And OptionGroup2= 9
Text224 = "4 and 9"
 
Case OptionGroup1 = 4 And OptionGroup2= 10
Text224 = "4 and 10"
 
 
Case OptionGroup = 5 And OptionGroup2 = 6
Text224 = "5 and 6"
 
Case OptionGroup1 = 5 And OptionGroup2= 7
Text224 = "5 and 7"
 
Case OptionGroup1 = 5 And OptionGroup2= 8
 
Text224 = "5 and 8"
 
Case OptionGroup1 = 5 And OptionGroup2= 9
Text224 = "5 and 9"
 
Case OptionGroup1 = 5 And OptionGroup2= 10
Text224 = "5 and 10"
 
 End Select
 
End Sub
 

 
 
Private Sub OptionGroup2_AfterUpdate()
 
Select Case True
 
Case OptionGroup2 = 6 And OptionGroup1 = 1
Text224 = "6 and 1"
 
Case OptionGroup2 = 6 And OptionGroup1= 2
Text224 = "6 and 2"
 
Case OptionGroup2 = 6 And OptionGroup1= 3
Text224 = "6 and 3"
 
Case OptionGroup2 = 6 And OptionGroup1= 4
Text224 = "6 and 4"
 
Case OptionGroup2 = 6 And OptionGroup1= 5
Text224 = "6 and 5"
 
 
 
Case OptionGroup2 = 7 And OptionGroup1 = 1
Text224 = "7 and 1"
 
Case OptionGroup2 = 7 And OptionGroup1= 2
Text224 = "7 and 2"
 
Case OptionGroup2 = 7 And OptionGroup1= 3
Text224 = "7 and 3"
 
Case OptionGroup2 = 7 And OptionGroup1= 4
Text224 = "7 and 4"
 
Case OptionGroup2 = 7 And OptionGroup1= 5
Text224 = "7 and 5"
 
 
Case OptionGroup2 = 8 And OptionGroup1 = 1
Text224 = "8 and 1"
 
Case OptionGroup2 = 8 And OptionGroup1= 2
Text224 = "8 and 2"
 
Case OptionGroup2 = 8 And OptionGroup1= 3
Text224 = "8 and 3"
 
Case OptionGroup2 = 8 And OptionGroup1= 4
Text224 = "8 and 4"
 
Case OptionGroup2 = 8 And OptionGroup1= 5
Text224 = "8 and 5"
 
 
 
Case OptionGroup2 = 9 And OptionGroup1 = 1
Text224 = "9 and 1"
 
Case OptionGroup2 = 9 And OptionGroup1= 2
Text224 = "9 and 2"
 
Case OptionGroup2 = 9 And OptionGroup1= 3
Text224 = "9 and 3"
 
Case OptionGroup2 = 9 And OptionGroup1= 4
Text224 = "9 and 4"
 
Case OptionGroup2 = 9 And OptionGroup1= 5
Text224 = "9 and 5"
 
 
Case OptionGroup2 = 10 And OptionGroup1 = 1
Text224 = "10 and 1"
 
Case OptionGroup2 = 10 And OptionGroup1= 2
Text224 = "10 and 2"
 
Case OptionGroup2 = 10 And OptionGroup1= 3
Text224 = "10 and 3"
 
Case OptionGroup2 = 10 And OptionGroup1= 4
Text224 = "10 and 4"
 
Case OptionGroup2 = 10 And OptionGroup1= 5
Text224 = "10 and 5"
 
End Select
 
End Sub
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:18
Joined
May 7, 2009
Messages
19,169
Form's After Update will not fire unless you are saving the form.
use the control's After Update:
Code:
Private Sub OptionGroup1_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub OptionGroup2_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub UpdateTextbox()
Select Case True
    Case OptionGroup1=1 And OptionGroup2=6
        Textbox = "Result for option 1 and 6 are selected."
    Case OptionGroup1=1 And OptionGroup2=7
        Textbox = "Result for option 1 and 7 are selected."
and so on...
End Select
End Sub
 

Jediknight

New member
Local time
Yesterday, 21:18
Joined
Jul 11, 2019
Messages
15
Form's After Update will not fire unless you are saving the form.
use the control's After Update:
Code:
Private Sub OptionGroup1_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub OptionGroup2_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub UpdateTextbox()
Select Case True
    Case OptionGroup1=1 And OptionGroup2=6
        Textbox = "Result for option 1 and 6 are selected."
    Case OptionGroup1=1 And OptionGroup2=7
        Textbox = "Result for option 1 and 7 are selected."
and so on...
End Select
End Sub


This ^^^^^
Is working!!!!

Thank you !!! Thank you!!! Thank you !!
:)



Sent from my iPhone using Tapatalk
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:18
Joined
May 7, 2009
Messages
19,169
to tell you the truth, there is no difference with your code and mine.
anyway, cheers!
 

isladogs

MVP / VIP
Local time
Today, 01:18
Joined
Jan 14, 2017
Messages
18,186
I believe this lengthy code can be significantly simplified
Adapting arnel's improved version, would something like this work

Code:
Private Sub OptionGroup1_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub OptionGroup2_AfterUpdate()
Call UpdateTextbox
End Sub

Private Sub UpdateTextbox()
Select Case True
  
Case OptionGroup1 = 2 And OptionGroup2= 7
     Text224 = "A2, EXTREMELY HIGH"

Case Else
    Text224 = "Result for " & OptionGroup1 & " and " & OptionGroup2 & " are selected."

End Select
   
End Sub

That should be all the code needed
 

Cronk

Registered User.
Local time
Today, 12:18
Joined
Jul 4, 2013
Messages
2,770
Code could be made more efficient with nested select clauses (or if/thens)


Code:
select case optionGroup1
  case 1
     select OptionGroup2
       case 1
       case 2
       .....
    end select
  case 2
       select OptionGroup2
       case 1
       case 2
       .....
    end select
  case 3
   ....
end select
 

Micron

AWF VIP
Local time
Yesterday, 21:18
Joined
Oct 20, 2018
Messages
3,476
Textbox = "Result for option 1 and 7 are selected."
This is just a place holder for something else, yes? Because user obviously can see which they chose, and usually designer has no reason to provide info to user regarding the selections. So what is the final goal here, "do something if A1 and B2 is selected, do something else if A2 and B3 is selected, and so on? Or is it just to provide user with a textbox to show them what they ought to already know?

If the example is just a substitute for some other evaluation then it seems 25+25 case statements are required using the values and the method expressed. However, the case statements can possibly be only 25 as I already noted, by each set of values being such that combinations of choices cannot result in duplicate values, such as 0,1,2,3,4 and the other 10,20,30,40,50. If values are 1-5 in one group and 6-10 in the other, it is possible to get (e.g.) 11 from 1+10 or 4+7, hence the need for 50 tests. However, not if the values are as I described. The possible results are

10,11,12,13,14,20,21,22,23,24... which adds up to 25 possibilities, I think.

That all presumes that there is nothing going on in the form beyond what has been revealed. I figured an explanation of my prior post might be warranted given that the original post might not have been revealing its true nature. On the other hand, the interpretations of Colin et al might be spot on.
 

Users who are viewing this thread

Top Bottom