SemperSalvus
Programmer
If I can, I need to streamline this code. I am using a tab control to manage several hundred fields for an inspection application. Many of the fields have a "green, yellow, red" state for the inspector to choose, depending on how good or bad the particular inspection item is. The table values are "G" for Green, "Y" for Yellow, and "R" for Red. I have code changing both the back and forecolor of the label on the afterupdate event of the list box control. The event will call 2 different functions, one for the backcolor and one for the forecolor.
My problem is that the code in the afterupdate event for each field, is still a little too long since it is taking me forever to develop the form. I have basically the same code being used for each field's afterupdate event. The name of the control is used 3 times within the code and is the only difference each time. Here is an example of the afterupdate event code and the functions:
Private Sub ctlDOCK_SURFACE_CRACKED_AfterUpdate()
Dim strARG As String
strARG = Me.ctlDOCK_SURFACE_CRACKED.Value
Call ChooseBackColor(strARG)
Me.lblDOCK_SURFACE_CRACKED.BackColor = QBColor(ChooseBackColor(strARG))
Call ChooseForeColor(strARG)
Me.lblDOCK_SURFACE_CRACKED.ForeColor = QBColor(ChooseForeColor(strARG))
End Sub
Private Function ChooseBackColor(strARG)
If strARG = "G" Then
ChooseBackColor = 2
ElseIf strARG = "Y" Then
ChooseBackColor = 14
ElseIf strARG = "R" Then
ChooseBackColor = 12
End If
End Function
Private Function ChooseForeColor(strARG)
If strARG = "G" Then
ChooseForeColor = 15
ElseIf strARG = "Y" Then
ChooseForeColor = 0
ElseIf strARG = "R" Then
ChooseForeColor = 0
End If
End Function
Is there some way I can trim down the afterupdate event code since I will have several hundred of these little procedures? I thought of using one call to another proc that passes on the name of the control as the argument? That other proc could call the 2 functions to determine the color. However, I could not figure out how to pass on the control name without having to retype that name within the afterupdate event. I could find no method to grab the name for this purpose though. Thanks.
My problem is that the code in the afterupdate event for each field, is still a little too long since it is taking me forever to develop the form. I have basically the same code being used for each field's afterupdate event. The name of the control is used 3 times within the code and is the only difference each time. Here is an example of the afterupdate event code and the functions:
Private Sub ctlDOCK_SURFACE_CRACKED_AfterUpdate()
Dim strARG As String
strARG = Me.ctlDOCK_SURFACE_CRACKED.Value
Call ChooseBackColor(strARG)
Me.lblDOCK_SURFACE_CRACKED.BackColor = QBColor(ChooseBackColor(strARG))
Call ChooseForeColor(strARG)
Me.lblDOCK_SURFACE_CRACKED.ForeColor = QBColor(ChooseForeColor(strARG))
End Sub
Private Function ChooseBackColor(strARG)
If strARG = "G" Then
ChooseBackColor = 2
ElseIf strARG = "Y" Then
ChooseBackColor = 14
ElseIf strARG = "R" Then
ChooseBackColor = 12
End If
End Function
Private Function ChooseForeColor(strARG)
If strARG = "G" Then
ChooseForeColor = 15
ElseIf strARG = "Y" Then
ChooseForeColor = 0
ElseIf strARG = "R" Then
ChooseForeColor = 0
End If
End Function
Is there some way I can trim down the afterupdate event code since I will have several hundred of these little procedures? I thought of using one call to another proc that passes on the name of the control as the argument? That other proc could call the 2 functions to determine the color. However, I could not figure out how to pass on the control name without having to retype that name within the afterupdate event. I could find no method to grab the name for this purpose though. Thanks.