Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better way to write this code 1

Status
Not open for further replies.

cbiker

Programmer
Jul 2, 2003
35
US
I have a form with some labels that when you click them open different forms was looking for a way to show which lable was clicked by changing font color. Here is how I have it now but Im still learning and think there is probably a better way.
Me.LblBOD5.ForeColor = 16777215
Me.LblContacts.ForeColor = 0
Me.LblFlow.ForeColor = 0
Me.LblIndLimit.ForeColor = 0
Me.LblInfo.ForeColor = 0
Me.LblMemo.ForeColor = 0
Me.LblMetals.ForeColor = 0
Me.LblNAICS.ForeColor = 0
Me.LblPermitInfo.ForeColor = 0
Me.LblpH.ForeColor = 0
Me.LblRecycler.ForeColor = 0
Me.LblIUsDDF.ForeColor = 0
Me.LblSIUInfo.ForeColor = 0
Me.LblSIUInsp.ForeColor = 0
Me.LblSIUNotes.ForeColor = 0
Me.LblTSS.ForeColor = 0
Me.LblViolations.ForeColor = 0
Me.LblVOC.ForeColor = 0

All help is much appreciated.
Carl
 
How are ya cbiker . . . . .

[ol][li]In the [blue]Tag[/blue] property of the Labels of interest enter [purple]LC[/purple] (no quotes). You can group select and enter it once.[/li]
[li]In the [blue]code module[/blue] for the [blue]form[/blue], copy/paste the following:
Code:
[blue]Public Sub HiliteLabel(lblName As String)
   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acLabel And ctl.Tag = "LC" Then
         If ctl.Name = lblName Then
            ctl.ForeColor = 16777215
         Else
            ctl.ForeColor = 0
         End If
      End If
   Next
   
End Sub[/blue]
[/li]
[li]Next, in the [blue]OnCilck[/blue] event of the Labels of interest, copy/paste the following ([blue]you![/blue] substitute proper ames in [purple]purple[/purple]):
Code:
[blue]   Call HiliteLabel("[purple][b]YourLabelName[/b][/purple]")[/blue]
[/li][/ol]
[purple]Thats it . . . give it a whirl & let me know . . .[/purple]


Calvin.gif
See Ya! . . . . . .
 
Doing good Now
How are you TheAceMan1.....

Tryed it and it works. Now I have to studie it and learn how it works need to learn more about Access programing
Thank again you are the best.
 
cbiker . . . . .

While your studying, in [blue]VBE[/blue] help have a look at [purple]Collections . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
A variation on the theme

Code:
Private Sub cboCust_GotFocus()
    basHiLiteLabel Me.Controls("cboCust")
End Sub

Private Sub txtCompany_GotFocus()
    basHiLiteLabel Me.Controls("txtCompany")
End Sub
Private Sub txtInvoiceNo_GotFocus()
    basHiLiteLabel Me.Controls("txtCompany")
End Sub
Private Sub txtSC_GotFocus()
    basHiLiteLabel Me.Controls("txtSC")
End Sub
Private Sub txtSD_GotFocus()
    basHiLiteLabel Me.Controls("txtSD")
End Sub


Code:
Public Sub basHiLiteLabel(MyCtrl As Control)

   Dim ctl As Control

    For Each ctl In MyCtrl.Parent
        If (ctl.ControlType <> acCommandButton) Then
            ctl.BackColor = vbWhite
        End If
    Next

    MyCtrl.BackColor = vbGreen

End Sub

MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top