By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,762 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,762 IT Pros & Developers. It's quick & easy.

Option buttons don't appear selected in group

beacon
100+
P: 579
Hi everybody,

I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff member combo boxes.

I have an option group that has 4 option buttons for the user to indicate how many staff members to include. Once the user selects one of the option buttons, the appropriate number of combo boxes become enabled and contain the staff members for the correct program.

All of that works like a charm. The issue that I've run into is that when the user selects one of the option buttons, the option button doesn't appear to be selected, i.e. the option button doesn't turn green. I can tell the buttons work because the combo boxes become enabled and the value of the option buttons is entered on the underlying table.

The option group has a value of zero, staff one has 1, staff two has 2, and so on. If the user attempts to select a staff member before selecting a program, there's code that tells the user that they need to enter a program first and sets the focus on the program field.

Anyway, here's all the code that relates to these fields:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub optionGroup_AfterUpdate()
  3.  
  4.     ' resets the option button if the option button is selected before program
  5.     Me.optionGroup = Me.optionGroup.OldValue
  6.  
  7.     ' set the focus on the program field
  8.     Me.Program.SetFocus
  9.  
  10. End Sub
  11.  
  12. Private Sub optionGroup_BeforeUpdate(Cancel As Integer)
  13.  
  14.     Dim UserChoice
  15.  
  16.     ' check to see if program has been entered...notify the user...go to afterupdate()
  17.     If IsNull(Me.Program) Then
  18.         MsgBox "You must enter a program prior to selecting staff from a particular program", vbExclamation + vbOKOnly, "Program Required"
  19.         Exit Sub
  20.     End If
  21.  
  22.     UserChoice = [optionGroup].Value
  23.  
  24.     ' selects the appropriate number of combo boxes to enable/disable based on user selection
  25.     Select Case UserChoice
  26.     Case 1
  27.         Me.Staff1.Enabled = True
  28.         Me.Staff2.Enabled = False
  29.             If Me.Staff2.Enabled = False Then
  30.                 Me.Staff2.Value = Null
  31.             End If
  32.         Me.Staff3.Enabled = False
  33.             If Me.Staff3.Enabled = False Then
  34.                 Me.Staff3.Value = Null
  35.             End If
  36.         Me.Staff4.Enabled = False
  37.             If Me.Staff4.Enabled = False Then
  38.                 Me.Staff4.Value = Null
  39.             End If
  40.     Case 2
  41.         Me.Staff1.Enabled = True
  42.         Me.Staff2.Enabled = True
  43.         Me.Staff3.Enabled = False
  44.             If Me.Staff3.Enabled = False Then
  45.                 Me.Staff3.Value = Null
  46.             End If
  47.         Me.Staff4.Enabled = False
  48.             If Me.Staff4.Enabled = False Then
  49.                 Me.Staff4.Value = Null
  50.             End If
  51.     Case 3
  52.         Me.Staff1.Enabled = True
  53.         Me.Staff2.Enabled = True
  54.         Me.Staff3.Enabled = True
  55.         Me.Staff4.Enabled = False
  56.             If Me.Staff4.Enabled = False Then
  57.                 Me.Staff4.Value = Null
  58.             End If
  59.     Case 4
  60.         Me.Staff1.Enabled = True
  61.         Me.Staff2.Enabled = True
  62.         Me.Staff3.Enabled = True
  63.         Me.Staff4.Enabled = True
  64.     Case Else
  65.         Me.Staff2.Enabled = False
  66.             If Me.Staff2.Enabled = False Then
  67.                 Me.Staff2.Value = Null
  68.             End If
  69.         Me.Staff3.Enabled = False
  70.             If Me.Staff3.Enabled = False Then
  71.                 Me.Staff3.Value = Null
  72.             End If
  73.         Me.Staff4.Enabled = False
  74.             If Me.Staff4.Enabled = False Then
  75.                 Me.Staff4.Value = Null
  76.             End If
  77.     End Select
  78.  
  79. End Sub
  80.  
  81.  
  82. Private Sub Program_BeforeUpdate(Cancel As Integer)
  83.  
  84.     Dim programVal, strSQL
  85.  
  86.     programVal = Me.Program
  87.  
  88.     ' set a SQL string based on selection in program field
  89.     Select Case programVal
  90.     Case "CAP"
  91.         strSQL = "SELECT[tblStaffCAP].[Staff Name] FROM tblStaffCAP;"
  92.     Case "EEP"
  93.         strSQL = "SELECT[tblStaffEEP].[Staff Name] FROM tblStaffEEP;"
  94.     Case "GPP"
  95.         strSQL = "SELECT[tblStaffGPP].[Staff Name] FROM tblStaffGPP;"
  96.     Case "RIDR"
  97.         strSQL = "SELECT[tblStaffRIDR].[Staff Name] FROM tblStaffRIDR;"
  98.     Case "SBP"
  99.         strSQL = "SELECT[tblStaffSBP].[Staff Name] FROM tblStaffSBP;"
  100.     End Select
  101.  
  102.     ' set the rowsource equal to the SQL string based on program
  103.     Me.Staff1.RowSource = strSQL
  104.     Me.Staff2.RowSource = strSQL
  105.     Me.Staff3.RowSource = strSQL
  106.     Me.Staff4.RowSource = strSQL
  107.  
  108. End Sub
  109.  
It's like the option buttons are reset when the SQL is set. I don't understand if or how I can fix it.

Thanks for the help,
beacon
Dec 5 '08 #1
Share this Question
Share on Google+
2 Replies


beacon
100+
P: 579
Nevermind...I figured it out.

My afterupdate() event was resetting the optiongroup value everytime and putting the focus on the program field.

I changed it to the following and everything is working now:
Expand|Select|Wrap|Line Numbers
  1. Private Sub optionGroup_AfterUpdate()
  2.  
  3.     If IsNull(Me.Program) Then
  4.         Me.optionGroup = Me.optionGroup.OldValue
  5.         Me.Program.SetFocus
  6.     End If
  7.  
  8. End Sub
  9.  
Sorry for wasting everyone's time.

- beacon
Dec 5 '08 #2

NeoPa
Expert Mod 15k+
P: 31,489
No worries Beacon. Thanks for popping back with the solution :)
Dec 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.