Control Key Pressed

R

Rod

All,

I have this code in a module, I got it from Dev Ashish http://www.mvps.org/access/. I have modified it a little bit. The ToolTip will now give the name of the RecordSource and the Field name. This works great but I only want to show this tooltip when the user hold the CTRL key down. Right now it works great as it is in the OnCurrent so I do not need to add it to each control on the form. Is there any why I can check to see if the use has the CTRL key pressed then the tooltip will be the RecordSource.FieldName otherwise I want the default ToolTip, what I built to display.

TIA,
Rodger

Public Sub sShowToolTip(frm As Form)
Dim ctl As Control, i As Integer, myTip

On Error Resume Next
For Each ctl In frm.Controls

With ctl
myTip = frm.RecordSource & "." & .Name
.ControlTipText = myTip
End With

Next ctl
Set ctl = Nothing: Set frm = Nothing
End Sub


'And then on my OnCurrent for a form I have . . . . .

Private Sub Form_Current()
Call sShowToolTip(Me)
End Sub
 
G

Guest

Look in VBA Help for the KeyDown event. I think if you read through that, it
may answer your question.
 
R

Rod

The problem with the OnKeyDown Event is that the record would need to be
selected as I need the OnKeyDown Event on the form and not the individual
control. If I call my Function sShowToolTip from the onKeyDown event it
keeps running the code while I have the CTRL key down then when I let off
the CTRL key I can hover over my controls and see the
RecordSource.ControlName. What I want is to hold the CTRL key and hover
over the control and see RecordSource.ControlName then when I do not have
the CTRL key pressed I want to see the ToolTip I gave it in the properties
when I set the form up. I did not want to have to go through each control on
my form to check to see if I have the CTRL key pressed and then to have to
change the tooltip to the RecordSource.ControlName. Does this make sense?

Klatuu said:
Look in VBA Help for the KeyDown event. I think if you read through that, it
may answer your question.
http://www.mvps.org/access/. I have modified it a little bit. The ToolTip
will now give the name of the RecordSource and the Field name. This works
great but I only want to show this tooltip when the user hold the CTRL key
down. Right now it works great as it is in the OnCurrent so I do not need
to add it to each control on the form. Is there any why I can check to see
if the use has the CTRL key pressed then the tooltip will be the
RecordSource.FieldName otherwise I want the default ToolTip, what I built to
display.
 
G

Guest

Turns out, it's not that difficult. The MouseMove event has a Shift
argument. It the Ctrl key is down when the event is fired, Shift will have a
value of 2. So, to avoid a bunch of redundent code, you can use the second
function here to decide what the Tooltip will display. The only issue is,
you will need to put the text for the tool tip in the Tag proerty instead of
the ControlTipText property or the first time you what to display the control
source, it will get overwritten. So here is how you call it from the
MoveMove event:
Pass the Shift argument and the name of the control

Private Sub Combo3_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Call WhatToShow(Shift, "Combo3")
End Sub

Based on whether the Ctrl key is down, it will display either the Control
Source property or the tag property

Private Function WhatToShow(intWhich As Integer, strControlName As String)

With Me.Controls(strControlName)
If intWhich = 2 Then
.ControlTipText = .ControlSource
Else
.ControlTipText = .Tag
End If
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top