Option Group Problem (1 Viewer)

TheSearcher

Registered User.
Local time
Today, 04:54
Joined
Jul 21, 2011
Messages
304
I have a form that contains an option group consisting of 5 option buttons. The option group is called opt_IncidentType.
On the form's Open event I run a query which opens a recordset containing the value from a field called Incident_Type.
This is my code:

Code:
Select Case rs("Incident_Type")
        Case "Danielle's Law (911)"
            Me.opt_IncidentType.Value = 1
        Case "Transport to Hospital (Not 911)"
            Me.opt_IncidentType.Value = 2
        Case "Stephen Komnino's Law (abuse/neglect/exploitation)"
            Me.opt_IncidentType.Value = 3
        Case "Stephen Komnino's Law (moderate or major injury)"
            Me.opt_IncidentType.Value = 4
        Case Else
            Me.opt_IncidentType.Value = 5
            Me.txt_Other.Visible = True
            Me.txt_Other.Value = rs("Incident_Type")
    End Select
The problem is that none of the option buttons is ever selected. Shouldn't assigning a value to the button (Me.opt_IncidentType.Value = 1) cause it to show as selected?

Thanks,
TS
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:54
Joined
Oct 29, 2018
Messages
21,358
I think so. Have you stepped through your code to make sure it is assigning something to the Option Group?
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:54
Joined
Sep 21, 2011
Messages
14,050
I have just tried it and it does?
 

onur_can

Active member
Local time
Today, 01:54
Joined
Oct 4, 2015
Messages
180
There is a situation that prevents you from selecting in the option group, there may be a crash or conflict, the alternative group is active, etc. you need to examine your application.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:54
Joined
Sep 12, 2006
Messages
15,614
I would leave the "value" off.
Try just this.

Code:
Me.opt_IncidentType= 1

It might be that you want the load event, or even the current event. Maybe the open even is too early.
Is there a default value for the option group? Try removing that also.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:54
Joined
Jul 9, 2003
Messages
16,245
I think you should consider storing the actual option group value in a table. Have the the option group value 1,2,3,4,5 linked to a lookup table so you can use the information in another form or a report. Something similar to this attached...
 

Attachments

  • tblEmegencyResponse1a.zip
    313.1 KB · Views: 239

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:54
Joined
Jul 9, 2003
Messages
16,245
I think you should consider storing the actual option group value in a table.

There is a major problem in storing information like that in an option group selection. Although the option group selections might seem set in stone, it is nearly always the case that they are not. If they need updating, if there is a new one added at a later date, then the job cannot be done by the anyone, it can only be done by the programmer. A safer option is to use a combobox, or a list box, because with these types of objects on your form you can arrange for the them to be updated by a supervisor instead of a programmer.
 

TheSearcher

Registered User.
Local time
Today, 04:54
Joined
Jul 21, 2011
Messages
304
I really appreciate all of your help. I've worked with option groups many times and never ran into these problems. In the following code my first message box returns the correct value ("car transport"), my second message box tells me that I'm in the "else" statement but:
  • option 5 is not selected
  • txt_Other is not visible
  • txt_Other does not contain a value
Code:
MsgBox rs("Incident_Type")    '*** This equals "car transport"

Select Case rs("Incident_Type")
        Case "Danielle's Law (911)"
            Me.opt_IncidentType.Value = 1
        Case "Transport to Hospital (Not 911)"
            Me.opt_IncidentType.Value = 2
        Case "Stephen Komnino's Law (abuse/neglect/exploitation)"
            Me.opt_IncidentType.Value = 3
        Case "Stephen Komnino's Law (moderate or major injury)"
            Me.opt_IncidentType.Value = 4
        Case Else
            MsgBox "In case Else"
            Me.opt_IncidentType = 5
            Me.txt_Other.Visible = True
            Me.txt_Other.Value = rs("Incident_Type")
End Select

I appreciate Uncle Gizmo's idea of using a combo box instead - and I'll do that if I have to - but I just don't understand what's going on here! Why would none of the commands in the else statement work?
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:54
Joined
Sep 21, 2011
Messages
14,050
You need to debug.print rs("Incident_Type") OK, just seen the MSGBOX :(

I believe using the value is a better idea. What if the name of the law changed for some stupid reason?

Do you have Option Explicit at the top of your modules?
Does Me.txt_Other exist?
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:54
Joined
May 21, 2018
Messages
8,463
but I just don't understand what's going on here! Why would none of the commands in the else statement work?
It would help if you could post whole code or database. My only guess is that it never gets to the Else case. Do you have error checking.
My guess is that rs("Incident_Type") throws an error and you probably have bad error checking like resume next and thus falls through the code. No button is ever selected.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 08:54
Joined
Sep 12, 2006
Messages
15,614
I really appreciate all of your help. I've worked with option groups many times and never ran into these problems. In the following code my first message box returns the correct value ("car transport"), my second message box tells me that I'm in the "else" statement but:
  • option 5 is not selected
  • txt_Other is not visible
  • txt_Other does not contain a value
Code:
MsgBox rs("Incident_Type")    '*** This equals "car transport"

Select Case rs("Incident_Type")
        Case "Danielle's Law (911)"
            Me.opt_IncidentType.Value = 1
        Case "Transport to Hospital (Not 911)"
            Me.opt_IncidentType.Value = 2
        Case "Stephen Komnino's Law (abuse/neglect/exploitation)"
            Me.opt_IncidentType.Value = 3
        Case "Stephen Komnino's Law (moderate or major injury)"
            Me.opt_IncidentType.Value = 4
        Case Else
            MsgBox "In case Else"
            Me.opt_IncidentType = 5
            Me.txt_Other.Visible = True
            Me.txt_Other.Value = rs("Incident_Type")
End Select

I appreciate Uncle Gizmo's idea of using a combo box instead - and I'll do that if I have to - but I just don't understand what's going on here! Why would none of the commands in the else statement work?

If you are getting to the "else", and your option group doesn't have an option 5, (ie, a button with a value of 5) this will error, unless you are ignoring run time errors. (on error resume next). I would trace the program execution to see exactly what happens.
 

TheSearcher

Registered User.
Local time
Today, 04:54
Joined
Jul 21, 2011
Messages
304
I appreciate all of your help! I used the option group value as suggested by Uncle Gizmo and Gasman and that worked. I still don't understand why my original code didn't work. Logically, I believe it should have. But I'm not going to argue with success. Thanks to all!
 

Users who are viewing this thread

Top Bottom