We help IT Professionals succeed at work.

Insert code for the double click event

sstampf
sstampf asked
on
478 Views
Last Modified: 2013-11-28
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

Comment
Watch Question

Commented:
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.
CERTIFIED EXPERT

Author

Commented:
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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:


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
CERTIFIED EXPERT

Author

Commented:
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).
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"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
CERTIFIED EXPERT

Author

Commented:
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?****
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"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
CERTIFIED EXPERT

Author

Commented:
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
 
Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Author

Commented:
Many thanks for your help and patience. Its working nicely and I also got to learn a new thing.
CERTIFIED EXPERT

Author

Commented:
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?****
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"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
CERTIFIED EXPERT

Author

Commented:
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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"..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
CERTIFIED EXPERT

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.