Link to home
Start Free TrialLog in
Avatar of sstampf
sstampfFlag for India

asked on

Insert code for the double click event

Hi,

I have a form which has many controls. For each of these controls I want to add a piece of code for their double click event. I want to call a procedure when any of these control is double clicked. The number of controls is too much and I can't do that manually so I am looking for some automation. I have build the code for one of the control (see attached code). I want similar codes for all the controls. Is this possible? Please help.

Thanks
Private Sub Recent_Hire_Date_DblClick(Cancel As Integer)
call sUpdate()
End Sub

Open in new window

Avatar of Ramanhp
Ramanhp
Flag of India image

suggesstion:
select all your controls,
give a single name to the control
this will create array of controls
now, the same code will get executed for all your controls
moreover, their display names would remain intact.
Avatar of sstampf

ASKER

Thanks for your suggestion Raman, but when I am selecting multiple items the option to set their name is not available (screenshot below). Further, I would like to retain the original name of each control because I am using it at some other place in my code.
untitled.JPG


1) Create your function, lets call it
mMyDblClickFx()

2) Select one control, and set the Control property sheet to the Events tab.

3) Now select ALL the controls of interest with your mouse

4) Pasted in the function name on the  On Dbl Click event line like so:

=mMyDblClickFx()

Done.

Now, all of these controls will have this function name.

mx
Avatar of sstampf

ASKER

Actually I am planning to implement a sub procedure and not a function on the double click event of these controls. Further, the controls are placed on different tabs (right now I have about 6 pages in the tab and it will keep growing).
Right now I am following the following method:
I am selecting each control and then building the double click event where I am pasting just one line of code (where I am calling that sub procedure by passing the argument).
"Actually I am planning to implement a sub procedure "
Why.  You can't call a Sub from the event procedure line.  You are doing this the hard way.  I personally never use Subs, as there is no advantage to doing so.  Even if I don't need to return a value, I use a Function ...because down the road, I may want to return a value.  

mx
"Further, the controls are placed on different tabs (right now I have about 6 pages in the tab "
Still, it would take me less than a minute to populate the Dbl Click invent for all the controls using the method I described.

mx
Avatar of sstampf

ASKER

Actually what I am doing here is this:
I have build a data dictionary which contains the details about all the data items I am showing on the form (because the number is too high so we need to keep a definition in place). I have build a form for that data dictionary and whenever any user double clicks on a control then that form opens and is fileterd down to the definition of that particular data item. Right now I am using the code below:
Private Sub Decline_Reason_DblClick(Cancel As Integer)
Call sDataDictionary(Me.ActiveControl.Name)
End Sub
Sub sDataDictionary(strItemName As String)
DoCmd.OpenForm "frmDataDictionary", , , "[Data Element Name]= '" & strItemName & "'"
End Sub
Can I acheive the same result using functions? It would be great if that is possible. Can you please help.
****Also I would be thankful if you can suggest some better way to acheive the same result. Double clicking is not possible for check boxes (as that will change the check box value) and there are several check boxes as well on my form. Right now I am not providing the data definition for any of the check boxes. Can I have some code which will help me simulate the windows help system where we click on a question mark and then the mouse pointer/cursor will change and then we will click on a control and its definition will be show? Should I open a new related question for that?****
 
"Can I acheive the same result using functions? "

Sure

Function sDataDictionary(strItemName As String)
DoCmd.OpenForm "frmDataDictionary", , , "[Data Element Name]= '" & strItemName & "'"
End Function

btw ... a check box does have a Dbl Click event, and it will trigger if you double click it.

Like the CHP says here in LA ... "Click It Or Ticket"

mx
Avatar of sstampf

ASKER

Many thanks Joe.
Please help regarding how to pass argument to this function.
Also I think that you misunderstood when I said that Double Clicking is not possible for Check Boxes.....what I meant to say was that double clicking will change the value of the check box so I don't want to implement that
 
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sstampf

ASKER

Many thanks for your help and patience. Its working nicely and I also got to learn a new thing.
Avatar of sstampf

ASKER

Regarding my comment above, please advice if you can help me design such a solution so that I can go ahead and open a new question (I am pasting the comments below once again)
****Also I would be thankful if you can suggest some better way to acheive the same result. Double clicking is not possible for check boxes (as that will change the check box value) and there are several check boxes as well on my form. Right now I am not providing the data definition for any of the check boxes. Can I have some code which will help me simulate the windows help system where we click on a question mark and then the mouse pointer/cursor will change and then we will click on a control and its definition will be show? Should I open a new related question for that?****
"Many thanks for your help and patience. Its working nicely and I also got to learn a new thing. "

You are welcome ...

I might note the each control has a ControlTip Text property ... such that when hovering over the control, whatever text you enter is displayed after a short delay.  Are you aware of this ?

mx
Avatar of sstampf

ASKER

Yes I am, but then My Data Dictionary has a whole lot of information.............btw can you please tell me if there is some fast way of updating the controltip for all the controls so that I can atleaste provide some basic information for controls when the user hover over it.......if VBA is a way then let me know so that I can open a new question for that...........actually there are so many controls that it is not possible for me to type in the control tip text
Many Thanks
"..if VBA is a way then let me know so that I can open a new question for that"

Definitely.  Yes, post a new Q for that.

Also, you might want to look at this:

http://www.lebans.com/tooltip.htm

mx
Avatar of sstampf

ASKER

I have opened a new question. Please help:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24898698.html
Thanks Again