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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing multiple labels backcolor at the same time

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hey guys
I am building a menu bar with eight categories and the way it works is that I have eight labels one for each category and if you click on one category 3 additional subcategories appear under the first category, the subcategories were in visible and is set to be visible when I click on the label for the first category and then becomes invisible when I click on the next category. I also have it set to on mouse move the backcolor turns yellow and the forecolor red every time I move my mouse on any one label.
The problem I am having is that there are a lot of labels and that means a lot of code to write. is there any way to have it tell the computer that for every label my mouse moves over to have the backcolor change yellow and the forecolor change red and when my mouse moves to another label to have it go back to it's original colors.
let me know if there is another way around this or else I have to write a lot of code.

This is what my menu bar looks like

-------------------------------------------------------
Categ1|Categ2|Categ3|Categ4|Categ5|Categ6|Categ7|Categ8|
------
Sub1 |<-These are the submenus that have visible set to
------ &quot;False&quot; and when you click on Categ1 their visible
Sub2 | is set to &quot;True&quot; When your mouse moves on one of
------ them the back color changes on which ever label
Sub3 | your mouse is on.
------
 
Try using the ControlType function and writing this into a function that ignores the labelname but uses the type!

Look under help for a worked example
 
I was looking around for control type function in help but couldn't find it can you give me an example
 
Hi
These are the types you can work with:
Constant Control
acLabel Label
acRectangle Rectangle
acLine Line
acImage Image
acCommandButton Command button
acOptionButton Option button
acCheckBox Check box
acOptionGroup Option group
acBoundObjectFrame Bound object frame
acTextBox Text box
acListBox List box
acComboBox Combo box
acSubform Subform/subreport
acObjectFrame Unbound object frame or chart
acPageBreak Page break
acPage Page
acCustomControl ActiveX (custom) control
acToggleButton Toggle button
acTabCtl Tab

Here's the example:
The following example examines the ControlType property for all controls on a form. For each label and text box control, the procedure toggles the SpecialEffect property for those controls. When the label controls' SpecialEffect property is set to Shadowed and the text box controls' SpecialEffect property is set to Normal and the AllowAdditions, AllowDeletions, and AllowEdits properties are all set to True, the intCanEdit variable is toggled to allow editing of the underlying data.

Sub ToggleControl(frm As Form)
Dim ctl As Control
Dim intI As Integer, intCanEdit As Integer
Const conTransparent = 0
Const conWhite = 16777215
For Each ctl in frm.Controls
With ctl
Select Case .ControlType
Case acLabel
If .SpecialEffect = acEffectShadow Then
.SpecialEffect = acEffectNormal .BorderStyle = conTransparent intCanEdit = True Else .SpecialEffect = acEffectShadow
intCanEdit = False End If
Case acTextBox
If .SpecialEffect = acEffectNormal Then .SpecialEffect = acEffectSunken
.BackColor = conWhite
Else .SpecialEffect = acEffectNormal
.BackColor = frm.Detail.BackColor
End If
End Select
End With
Next ctl
If intCanEdit = False Then
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
End If
End Sub

Good Luck
 
WOW thanks for your help but I have not dealt with functions before in access

Question1
Is there a website that I could go through that can show me how to create functions or is there a book that will help me.
Question2
I kind of understand what you are doing with the function but I am not sure How to write one based on what I want to do How would tell the application that when my mouse is over a label the forecolor is red and the backcolor is yellow and when my mouse is not over the label the forecolor should be white and the backcolor should be blue.
Question3
Where would I put the function do I have to create a module and if I do how do I attach the module to the form or database that I want to use.

Sorry for my ignorance but I have only been working with access for less than a year and up to now I have been writing my forms using vba I have not yet learned modules or how to create functions.

Thanks for any help that you can give me.
 
I created a module with a function but I am not sure why it is not working this is the code

Function fcolor()
If acLabel.forcolor = vbWhite Then
acLabel.forcolor = vbRed
ElseIf acLabel.forcolor = vbRed Then
acLabel.forcolor = vbWhite
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top