473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Option buttons don't appear selected in group

beacon
579 512MB
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
2 3375
beacon
579 512MB
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
32,556 Expert Mod 16PB
No worries Beacon. Thanks for popping back with the solution :)
Dec 9 '08 #3

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

Similar topics

3
by: Edward | last post by:
I have a data entry form that allows the user to navigate around entirely using the keyboard. However, it contains various option button controls which are in the tab order. Whenever they are...
2
by: PM | last post by:
I have a question about option buttons and their values. I have many option buttons on my forms, each set contained in their own group boxes. I simply want to be able to give them a value,...
2
by: Omey Samaroo | last post by:
I have had many questions answered in this forum and I am trusting that one of the readers may help me find a simple solution. (1) Using a field called Date_Hired (type: Date/Time), how do I use...
0
by: Robert | last post by:
Stephen, I think I figured out the problem. I was able to get Check Boxes and Option Buttons to work on my form by TURNING OFF RECORD SELECTORS on the form. Not sure why this would make a...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
5
by: Killer42 | last post by:
Hi all. I'm coming from a VB6 background so this is just confusing me a little. I have a form where the user can select one of a number of years to search. The selection doesn't relate directly to...
1
by: MAIjah | last post by:
Sorry, just a newbie and what I call a 'bruteforce' programmer. I'm using a VBform in EXCEL to pass info to a worksheet. I have 7 option buttons (exclusive?, only one can be true) and want to...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
0
by: Nathan Sokalski | last post by:
I have a DropDownList in which I set the SelectedIndex property in my code. However, when I run a debug it does not appear selected (actually, none of the ListItems are even visible in the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.