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

Text color change on Mouseover 3

Status
Not open for further replies.

air1jcw

Technical User
Jan 23, 2003
30
US
I need to be able to "highlight" the text in a label during mouseover on an ACCESS form. I would like to be able to change the text color to blue when the mouse moves over the label - OR change the pointer to the hand pointer on mouse over. If I can get the exact code for this and where to put it (module or event procedure) would save me and maybe get me promoted!!! I am using Access 2002/XP.
THANKS in advance!!!
 
um.. I don't know why, but your post seriously bothers me on many levels. I'm going to answer you despite the fact that I believe you should already know this - especially if this would get you a promotion.

Private Sub Lbl_1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > 0 And Y > 0 And X < (Me.Lbl_1.Width - (Me.Lbl_1.Width / 3)) And Y < (Me.Lbl_1.Height - (Me.Lbl_1.Height / 3)) Then
Me.Lbl_1.FontBold = True
Else
Me.Lbl_1.FontBold = False
End If
End Sub

This works for a LABEL named lbl_1, just replace lbl_1 with your lable name, and put this on it's mousemove event.

Randall Vollen
National City Bank Corp.

Just because you have an answer - doesn't mean it's the best answer.
 
To see an working example of this, download the Accessweb file Not only does it contain the code for doing this (check the design of the main form) but there are loads of other articles in the file that will help you every day.

hth

Ben

----------------------------------------------
Ben O'Hara &quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Being the nice guy that I am, I also wrote this for you:

Option Compare Database

'This is my highlight/bold/whatever function for a mouseover
Type objSize
intXLimit As Single
intYLimit As Single
End Type

Public Function fHighlightMouseOver(myObject As Object, Xpos As Single, YPos As Single)

Dim objPassed As objSize

With CodeContextObject
objPassed.intYLimit = Forms(.Name)(myObject.Name).Height * 2 / 3
objPassed.intXLimit = Forms(.Name)(myObject.Name).Width * 2 / 3
If Xpos > 0 And YPos > 0 And Xpos < objPassed.intXLimit And YPos < objPassed.intYLimit Then
Forms(.Name)(myObject.Name).FontBold = True
Else
Forms(.Name)(myObject.Name).FontBold = False
End If
End With

End Function

Call it by doing the following:

Call fHighlightMouseOver(Me.Lbl_1, X, Y)

just change me.lbl_1 with me.[your lable name]


Randall Vollen
National City Bank Corp.

Just because you have an answer - doesn't mean it's the best answer.
 
FYI for your color blue thing, (I did bold I red your post wrong) but you can just change the following lines:

Forms(.Name)(myObject.Name).FontBold = True
to:
Forms(.Name)(myObject.Name).foreColor = vbblue

and
Forms(.Name)(myObject.Name).FontBold = false
to:
Forms(.Name)(myObject.Name).forecolor = vbblack



Randall Vollen
National City Bank Corp.

Just because you have an answer - doesn't mean it's the best answer.
 
Hi,

You can use this. Put these constants in general declarations of your form:
Code:
Const conBlack As Long = 0
Const conBlue As Long = 16711680
Call this in On Mouse Move for any visible sections (Detail, FormHeader, FormFooter, Form)
Code:
Sub ResetLabelColours()
    Dim ctl As Control
    
    For Each ctl In Controls
        If ctl.ControlType = acLabel Then
            ctl.ForeColor = conBlack
            ctl.FontBold = False
        End If
    Next
End Sub
Call this in On Mouse Move for all labels (in the format:
Code:
HighLight Label1
)
Code:
Sub Highlight(ctl As Control)
    ctl.ForeColor = conBlue
    ctl.FontBold = True
End Sub

Set all labels to have the text centre-aligned, so it doesn't look funny when it goes bold.

Dean :)
 
Dean,

I stumbled on this post while searching for other stuff. I've been looking for ways to &quot;Jazz-up&quot; my applications and I really like your solution here. . .

Thanks!
Tru
 
Const conBlack As Long = 0
Const conBlue As Long = 16711680


Access VBA has these built in already: vbBlack and vbBlue
 
Hi DeanWilliams and all!

I qoute: &quot;Call this in On Mouse Move for any visible sections (Detail, FormHeader, FormFooter, Form)&quot;

how you CALL the sub, I TRIED IT AS I UNDERSTOOD YOU and the erroe i got is: &quot;Argument not optional&quot;

Private Sub Label1486_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Highlight
End Sub

thanks in advanced
CUOK
 
I tried this code on some controls (textboxes and Labels) that have been disabled and it didn't seem to work. All I wanted to do was change the text Forecolor to black instead of the gray color when a control is disabled.

Any thoughts
 
Hi,

COUK: You have to include the name of the label:

Private Sub Label1486_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Highlight Label1486
End Sub


Then for each Section - e.g:

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ResetLabelColours Me
'Use 'Me' if you have made ResetLabelColours public as below
End Sub

and also in:

Private Sub Form_MouseMove(Button As Integer, Shift As Integer...

Private Sub FormFooter_MouseMove(Button As Integer, Shift As Integer...

etc....

Using ResetLabelColours Me, have the function in a global module and change the start of the function to:

Public Sub ResetLabelColours(frm As Form)
Dim ctl As Control

For Each ctl In frm.Controls....

Hope that clears it up.

Sterlecki: I don't think you can change the ForeColor of disabled controls.

Dean :)
 
Sterlecki,
You can't change control colours of disabled controls, but you can change control colours of disabled and locked controls. The caveat with that is the disabled style colours are not applied automatically, you need to do that yourself.

hth

Ben

----------------------------------------------
Ben O'Hara &quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Mr. Williams, I have some VBA code that I used to highlight controls in a similar manner as this (got help RoyVidar on greatly shortening the code). The code changes the border color in the Got_Focus() event.
I have a question based on the information you provided: is there a way to do a Do While loop so that every control will be set to a certain border color upon opening of the form... So, in other words, I want to do something like this:
Code:
Private Sub frmForm_OnLoad()
     Dim ctrl as Control
     DoWhile not last control
          For each ctrl
               ctrl.BorderColor=vbBlue
          Next ctrl
     End While
End Sub

Is this possible, or something like this?


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Code:
Private Sub frmForm_OnLoad()
     Dim ctrl as Control
          For each ctrl in Me.Controls
               ctrl.BorderColor=vbBlue
          Next ctrl
End Sub

Ben.

----------------------------------------------
Ben O'Hara &quot;Where are all the stupid people from...
...And how'd they get so dumb?&quot;
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Well, I tried that bit of code as follows 2 ways, adding to what I already had in Form_Open(), and another time in Form_Load(). In both cases, the code reads:
Code:
Dim ctrl As Control
     For Each ctrl In Me.Controls
         ctrl.BorderColor = 52479
     Next ctrl
And it is producing this error, and not loading the form:
[BLUE]The expression On Open you entered as the event property setting produced the following error: Procedure declaration does ot match description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a user defined function, or [Event Procedure}.
*There may have been an error evaluating the function, event, or macro.[/BLUE]
It gives this error, regardless of where I put the code. When I have it in the Form_Load() event, the entire code for both events is currently this:
Code:
Private Sub Form_Open(Cancel As Integer)
    Me.tabStatusAudit.Visible = False    
End Sub

Private Sub Form_Load(Cancel As Integer)
    Dim ctrl As Control
        For Each ctrl In Me.Controls
            ctrl.BorderColor = 52479
        Next ctrl
End Sub
Any ideas?


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Hi Stephen,

The error you are getting is because the Form_Load event doesn't have a Cancel argument. You Load event should be:
Code:
Private Sub [b]Form_Load()[/b]
    Dim ctrl As Control
    
    For Each ctrl In Me.Controls
        ctrl.BorderColor = 52479
    Next ctrl
End Sub
This should work.

Dean :)
 
Thanks for that piece - that worked on the Form_Load() event, but on the Form_Open() event, it doesn't seem to work unless there is a Cancel as Integer Statement - the remaining statement, that is). Now, Here is my code for the Form_Load() event, and I'm getting another error:
Code:
Private Sub Form_Load()
    Dim ctrl As Control
        For Each ctrl In Me.Controls
             ctrl.BorderColor = 52479
        Next ctrl
End Sub
I am getting the error on the line, ctrl.BorderColor = 52479
The error states:

[BLUE]Run-time error '438':
Object doesn't support this property or method
[/BLUE]

I noticed that when I entered the code, the BorderColor property was not listed in the pop-up menu of properties for that object. Any way to fix that? I already tried setting it to Me(ctrl).BorderColor, but get the same error.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Hi,

Yes the Form_Open event needs the Cancel argument. When creating events, instead of typing the declaration yourself, either do it by selecting them from the dropdown lists at the top of the VB Editor, or from the Property Sheet for the Form/Report. This will ensure the procedure is declared properly with the correct arguments.

The problem you are getting now is because you are cycling through all controls and some do not have borders (e.g: Command Buttons). So you need to check the ControlType property of the control first.

You can get a list of all options by pressing F2 in the VB Editor to bring up the Object Browser. In the find box type: acControlType and the options will be displayed in the members section.

Anyway...You can check what type each control is first, but an easier way to do is to just ignore the error if the property doesn't exist:
Code:
Private Sub Form_Load()
    On Error GoTo Err_Form_Load
    
    Dim ctrl As Control
    
    ' ... 
    ' ... Any other code
    
    On Error Resume Next
    For Each ctrl In Controls
        ctrl.BorderColor = 52479
        ctrl.BorderStyle = 1 ' Added to make Border Solid
    Next ctrl
    On Error GoTo Err_Form_Load
    ' ...
    ' ... Any other code

    Exit Sub
    
Err_Form_Load:
    MsgBox Err & ": " & Err.Description
    Err.Clear
End Sub
You may also need to play with the BorderStyle properties to make it Solid or whatever you want. Look in Access help for info.

Dean :)
 
Thanks much for your help on this. All the information looks most useful for both this problem, as well as future ones I'm sure I will encounter. Unfortunately, I may not have any more time to work on this project for at least a couple of weeks, maybe a month to month and a half. My primary job is auditing, and we are starting up quarterly audits now, which can be very time consuming. Anyway, as soon as I am able to try to fix this situation, I will do so, and will report back with my findings. I am very appreciative of your efforts to answer this question.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top