highlight an option label

OR.....

Me.MyControlName.Controls(0).Name

will also give you the name of the child label associated with the named control when used locally within a Form's Code Module.

But...

Can sometimes provide some nightmarish results when using this method to reference child Labels of controls within a Frame control (group).

.
 
Im not quit sure I know how your code works? I have 16 labels how would I inclue them into your code?

oxicottin, If the controls are all Radio Buttons and they are contained within a Frame control, it doesn't matter how many controls you have. The code will work with them all however, you will need to ensure that the child Label Name for each Radio button is named exactly the same except the last character which should be the number representing Option Value of Radio Button (Parent) control itself. For example:

Code:
[U]Parent Ctrl Name  |  Option Value  |  Child Label Name[/U]
Option1                    1            OptionLabel1
Option2                    2            OptionLabel2
Option3                    3            OptionLabel3
Option4                    4            OptionLabel4
[COLOR="DarkGreen"]..........                ..            ..............
..........                ..            ..............
..........                ..            ..............[/COLOR]
Option15                  15            OptionLabel15
Option16                  16            OptionLabel16

Now...the three code lines in the sample I provided which look like:

Me.Controls("Olabel" & v).ForeColor = vbRed
Me.Controls("Olabel" & v).BackColor = vbYellow
Me.Controls("Olabel" & v).BackStyle = 1

would need to be changed to:

Me.Controls("OptionLabel" & v).ForeColor = vbRed
Me.Controls("OptionLabel" & v).BackColor = vbYellow
Me.Controls("OptionLabel" & v).BackStyle = 1


The number in the Label name is not provided, the code takes care of that and it derives it from the Option Value of the Parent Control. The Variable v holds this value.

Hope this helps.

.
 
CyberLynx, I understand now! I have a problem though. I have a button named cmdClearNatureAndExtentGroup which uses Me.optNatureandExtentGroup = Null to clear the entire Option Group. When I click this button the last selection made is still yellow? Is there a way aroud this? Thanks!

Code:
Dim Ctrl As Control, i As Integer, v As Integer

  Set Ctrl = Me.optNatureandExtentGroup
  v = Ctrl.Value

  For i = 1 To Ctrl.Controls.Count - 1
      If Ctrl.Controls(i).ControlType = acLabel Then
         Ctrl.Controls(i).ForeColor = vbBlack
         Ctrl.Controls(i).BackStyle = 0   'Transparent
      End If
  Next i

  Me.Controls("optExtentGroup" & v).ForeColor = vbRed
  Me.Controls("optExtentGroup" & v).BackColor = vbYellow
  Me.Controls("optExtentGroup" & v).BackStyle = 1  'Solid

  Set Ctrl = Nothing
 
Sure.......Within the code for your command button:

Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).BackStyle = 0 'Transparent
Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).ForeColor = vbBlack

.
 
CyberLynx, I get an error cant find optExtentGroup when I added to my clear button cmdClearNatureAndExtentGroup? Also I use the check box chkIsThisInjury to enable the option group but if I advance to a new record the option group stays enabled and the check box is still checked. How would I fix that as well? Here is the DB so you can see...

Thanks!
 
Last edited:
This is because the Option Group is Nulled (cleared) before the Text ForeColor and the Background Color is changed.

When the optNatureandExtentGroup Option Group Control is Nulled to clar the Radio Buttons, the optNatureandExtentGroup.Value is set to Null which in turn does not properly fill the name requirements for the associated child Label of the Radio Button that is selected. No number is added to the Label name so.....the Label simply doesn't exit.

All you need to do is move the:

Me.optNatureandExtentGroup = Null

line of code just below the:

Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).BackStyle = 0 'Transparent
Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).ForeColor = vbBlack


lines of code, like this:

'//Sets labels back to normal
Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).BackStyle = 0 'Transparent
Me.Controls("optExtentGroup" & Me.optNatureandExtentGroup.Value).ForeColor = vbBlack


'//Clears Option Group
Me.optNatureandExtentGroup = Null

.
 
CyberLynx, that worked but it still isn’t working right? If I check the chkIsThisInjury to enable the option group and select a body part then scroll to another record then the option that I selected from the prior record is still highlighted yellow even though the option isn’t selected also, the check box chkIsThisInjury is still checked when it shouldn’t be and the option group is enabled when it shouldn’t be either. What am I missing :confused:

Thanks!
 
Create a Sub Procedure within the SubForm code module and name it SetBodyPart.

In this SetBodyPart Sub Procedure you should have code like the following:

Code:
Private Sub SetBodyPart ()
   Dim V as Integer
   
   Call ClearBodyParts

   V = Nz(Me.optNatureAndExtentGroup.Value, 0)
   
   If V > 0 then
      Me.Controls("optExtentGroup" & V).ForeColor = vbRed
      Me.Controls("optExtentGroup" & V).BackColor = vbYellow
      Me.Controls("optExtentGroup" & V).BackStyle = 1  'Solid
   End If
End Sub

In the code above you may have noticed that there is yet another Procedure call....to the ClearBodyParts Sub Procedure. The code within the ClearBodyParts Sub Procedure is identical to the code you had placed into the AfterUpdate event for the Option Group control named optNatureAndExtentGroup. It's the For/Next loop we want and instead of writing duplicate code, we'll make a sub procedure and call that instead.

Code:
Private Sub ClearBodyParts()
   Dim Ctrl As Control, i As Integer

   Set Ctrl = Me.optNatureandExtentGroup
  
   For i = 1 To Ctrl.Controls.Count - 1
       If Ctrl.Controls(i).ControlType = acLabel Then
          Ctrl.Controls(i).ForeColor = vbBlack
          Ctrl.Controls(i).BackStyle = 0   'Transparent
       End If
   Next i

   Set Ctrl = Nothing
End Sub

Now, because we have taken the For/Next loop code from within the optNatureAndExtentGroup_AfterUpdate event and copied it then placed it into the ClearBodyParts Sub Procedure, we no longer need the For/Next loop within the optNatureAndExtentGroup_AfterUpdate event. Instead we now replace it with with a call to the ClearBodyParts Sub Procedure. The code within the optNatureAndExtentGroup_AfterUpdate event should now look like this:

Code:
Private Sub optNatureAndExtentGroup_AfterUpdate()
  Call ClearBodyParts
  Call SetBodyPart
End Sub

Finally...in the OnCurrent event of the AccidentEntrySubform SubForm enter this line of code:

Call SetBodyPart

Now what will happen is this: As you scroll through the different records, the Body Parts section in Form will always be updated (proper highlighted label) to the Body Part stored for that record. Any previous highlight is automatically removed. If a New Record is put into play then No body parts are highlighted since a new record would contain no Option Value for the Body Parts group.

You will also want to place this line into the same OnCurrent event:

Call chkIsThisInjury_AfterUpdate

so as to ensure that the Form fields that are suppose to be disabled when there is no chkIsThisInjury selection when scrolling from record to record or when a new record is entered.

-------------------------------------

On Another Note:

In OnClick event of the optNatureAndExtentGroup Option Group (Frame) control, you have a lot of If/Then statements in play to store the Body Part Selected. Knowing now how to access the child Labels of the Radio Buttons contained within the group, you can eliminate all those If/Then statements and use only one.

Understandably, the child Labels don't really contain the Full name of the Body Part you want to store but, you can place that full name into the Tag property for each child label and pull from that property. The following code will eliminate all those If/Then Statements:

Code:
If Nz(Me.optNatureandExtentGroup.Value, 0) > 0 Then
   Me.txtBodyPartName = Me.Controls("optExtentGroup" & _
                       Me.optNatureandExtentGroup.Value).Tag
End If

Apply the same strategy to the code within the optClassicficationGroup controls' AfterUpdate event

Just a thought and this is only what I would do ..... the Radio buttons housed within the body images should not be visible. You already have leader lines to distinguish the Body Part and therefore the large circle for the Radio Button is not required. I think it's more pleasing to the eye that way. Simply Bring To Front the Image Controls (Format menu | Bring To Front) then select each leader line and bring those to front.

Once done, when a Body Part selection is made, all Radio Buttons become visible. When focus is removed from the Group, the Radio Buttons hide behind the Image control again. You may like the effect.

Nice Form by the way :)

.
 
CyberLynx, If I select the clear options button then I get an error that it cant find opExtentGroup0 which I have no 0. Is there a way this button can only be enabled or visible if an option is selected? I tried to move the Me.cmdClearNatureAndExtentGroup.Enabled = True to the option groups on click event and it worked BUT only if you clicked on a label it didn’t enable if an option was selected. I still can’t get the chk box chkIsThisInjury to work properly. I have tried your suggestions and still can’t get it to work when I scroll to the next record. Oh and you idea on the radio butions make perfect sence! :D Here is an updated DB version. Thanks!
 
Last edited:
If I select the clear options button then I get an error that it cant find opExtentGroup0 which I have no 0

Read Posting #26. The reason is explained there.

With regards to all you other questions, well, see your sample DB (slightly modified) attached to this post.

I have also added a simple Time Picker Form to the Sample DB. You can access it by Double-Clicking on the Time Of Incident Form TextBox. Take a close look at the Time Picker Form. Notice the Clock Icon at the top. Well that's really a Adobe Shockwave Flash file (.swf) of a working clock. You'll notice it contains the current time and the seconds ticking off. It's just there to show you how you can easily add Shockwave (.swf) files to your Database (reference to Shockwave Flash is required). The clock .swf file is with the sample DB.

Take a look at the returned Sample Database. Look at the code to see how I did things. This should keep you busy for a little while. :)

.
 

Attachments

For the search you want to carry out, I think you should create a Search Form. Based on items selected within the Search Form, create a SELECT dynamic query which will go against the tblMain Table and apply that query to the desired Report.

.
 
I'm glad you got it working oxicottin. I knew you could do it. ;)

.
 
CyberLynx, I have run into some problems and needed some help. First question is if I run a search for Third Party Accidents then I get no absolutely no results? When I run a search lets say I run a search in the “ Search Records By classification/Year” section using the criteria “Third Party” and year “2008” it will give me a result of ‘No records found” and I know there is one record in my table and it should show it but it doesn’t for some reason? Second question, When I run a search lets say I run a search in the “Search Records By classification/Year” section using the criteria “ANI” and “2008”. It will bring up a list of records. The first one belonging to a “H,Scott” record 242. If I click the button to view the record then the record will come up showing all the information except for the name. The reason is because this is the same form I use for new entries ect. and the name list runs from a query that only shows names that are current or employees that still work here. Is there a work around for this?

Thanks,
Chad
 

Attachments

I have run into some problems and needed some help. First question is if I run a search for Third Party Accidents then I get no absolutely no results? When I run a search lets say I run a search in the “ Search Records By classification/Year” section using the criteria “Third Party” and year “2008” it will give me a result of ‘No records found” and I know there is one record in my table and it should show it but it doesn’t for some reason?

This is becuase....if you actually look at the record in table you are missing something. Guess what it is. Make sure this sort of thing can not happen. For obvious reasons, it is a necessary field. Without this information the entire record is pretty much useless (well....to some degree).


Second question, When I run a search lets say I run a search in the “Search Records By classification/Year” section using the criteria “ANI” and “2008”. It will bring up a list of records. The first one belonging to a “H,Scott” record 242. If I click the button to view the record then the record will come up showing all the information except for the name. The reason is because this is the same form I use for new entries ect. and the name list runs from a query that only shows names that are current or employees that still work here. Is there a work around for this?

I suppose you could just pass a Flag to the AccidentEntry Form through the OpenArgs property when the Form is actually opened to Change the RowSource property of the cboEployeeName ComboBox. For example:

Where you make the call to open the AccidentEntry Form so as to display the Employee selected put this as the OpenArgs argument:

"InSearchMode"

or in other words:

DoCmd.OpenForm stDocName, , , stLinkCriteria, , , "InSearchMode"

Then in the OnOpen Event of the AccidentEntrySubform Form you would have this code:

Code:
If IsNull(Forms("AccidentEntry").OpenArgs) = False Then
   If Forms("AccidentEntry").OpenArgs = "InSearchMode" Then
      Me.cboEmployeeName.RowSource = "SELECT EmpID, LastName & ', ' & FirstName AS Expr1, DateOfHire, Status FROM tblEmployees;"
   End If
Else
  Me.cboEmployeeName.RowSource = "SELECT qryActiveInactiveEmployees.EmpID, [LastName] & ', ' & [FirstName] AS Expr1, qryActiveInactiveEmployees.DateOfHire FROM qryActiveInactiveEmployees;"
End If

Now....when the search is done and the AccidentEntry Form is opened, the Employee Combox box will contain ALL Employees (past and present). If the AccidentEntry Form is opened from any other fashion or location and "InSearchMode" is NOT passed in the OpenArgs argument then the Query is used again to fill the Employee Combo Box and only current employees are listed.

.
 
Cyberlynx, The reason there isnt anything is because that is outside contractors and thier name isnt in the list of employees and I have the txt box properties set so you cant add to the list "Limit to list = yes" I could however add an employee tha is named "Third Party" and when there is a third party then they would use that name. Any thoughts? I like the other idea and am going to try it tonight...

Thanks,
Chad
 
In general, it's irrelevant whether the person injured works at the plant or does not however, it is relevant that a persons ID number goes into the Employees field within the tblAccidents Table since doing so allows everything to function properly since this is how the structure is laid out.

When a person is injured (accident) or is almost injured (near miss accident) a Accident Investigation report is carried out so as to accomplish a few things:

1) To find out the cause and events leading to the Accident for both Company Records, Employee Compensation institutions relevant to that employee, Company Employees, and the Injured Employee him/her self;
2) To determine what measures can be taken to prevent the incident from happening ag6ain so that no one else will get injured;
3) To Inform others within the same environment of what to or not to do and that to watch out for;
4) Due Diligence on the part of the Company. Accident Investigations show proof of action on the part of the Company.

These are just a few reasons.

In a lot of plants the Accident Investigation is posted for other employees to see but the people named within the investigation are omitted for obvious anonymitical reasons. For plant Safety Committees and Management personnel, you would want to have the name visible so as to know involvement but for posting the names should not be in view.

For all intent and purposes perhaps consider having the Table contain a Name field that can contain the name of anyone, whether that person works at the plant or not. Anyone that is injured or there was a particular incident should be followed by a AI Report. So have a Employee ID field and the Employee Name Field. If you have he Employee ID then you don't need the Name but if there is no Employee ID then you just need the name. This can be handled from the Not In List event for the Employee Name Combo Box If not in list then prompt for person's Name and company he/she works for. Have your search also reference this information for the final output.

Anyway...that's one possibility. Something to think about.

.
 
You are the man! :D I appreciate all your well explained comments and every one has made sence to the point that I have implemented them into a database. I just want to thank you for your halp and comments!

Thanks,
Chad
 
CyberLynx, I have the database all finished and now im getting an error when I try to select anything from the AccidentEntrySubform. It only shows this message on the first item I select then it never comes up after on other items select on this record. It worked fine earler? The error says

You cant assign a value to this object
*The object may be a control on a read only form
*Object may be on a form that is open in design view
*The value may be to large for this field

Any Ideas why? Thanks!
 
Last edited:
This error is basically telling what the problem is. Ensure that none of the conditions the error specifies actually exist.

Off hand...I would say check the Master and Child links between the Main Form and Sub-Form. Are the Record ID's the same? No...then you have a issue there.

There is nothing in the Main Form except a few command buttons. Why even bother having the Links. If you need to reference the Record ID number of the current AI Report then merely reference it directly from the Sub-Form itself.

Get rid of the AccidentID Text Box on the Main Form and kill (delete) the Master and Child Links properties attached to your Sub-Form Control and your problem should be solved.

.
 
CyberLynx, That fixed it.. I got rid of the origional AccidentEntry form and re-named my AccidentEntrySubform "AccidentEntry" and then I moved all the buttons from the origional AccidentEntry over to the new one. One thing isnt working and its the code that if the employee wasnt current then it would show the entire list, Well its always showing the entire list even if the employee is current. I imagen its the code. I changed it to below because I have no subform anymore. What am I missing I just took out the subform code. Thanks!
Code:
If IsNull(Forms("AccidentEntry").OpenArgs) = False Then
   If Forms("AccidentEntry").OpenArgs = "InSearchMode" Then
      Me.cboEmployeeName.RowSource = "SELECT EmpID, LastName & ', ' & FirstName AS Expr1, DateOfHire, Status FROM tblEmployees;"
   End If
Else
  Me.cboEmployeeName.RowSource = "SELECT qryActiveInactiveEmployees.EmpID, [LastName] & ', ' & [FirstName] AS Expr1, qryActiveInactiveEmployees.DateOfHire FROM qryActiveInactiveEmployees;"
End If
 

Users who are viewing this thread

Back
Top Bottom