DoubleClick event

A

alex

Hello,
Using Access '03...

Is there a way to respond to the DoubleClick of ANY control on a form?

I thought this code might work, but no:

Private Sub Form_DblClick(Cancel As Integer)

'open Zoom box if user double clicks
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
DoCmd.RunCommand acCmdZoomBox
End If
Next ctl

End Sub

It does work in the individual on DoubleClick event. But if you have
10 controls, it seems silly to write the code 10 times.

Thanks,
alex
 
D

Dirk Goldgar

alex said:
Hello,
Using Access '03...

Is there a way to respond to the DoubleClick of ANY control on a form?

I thought this code might work, but no:

Private Sub Form_DblClick(Cancel As Integer)

'open Zoom box if user double clicks
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
DoCmd.RunCommand acCmdZoomBox
End If
Next ctl

End Sub

It does work in the individual on DoubleClick event. But if you have
10 controls, it seems silly to write the code 10 times.


You can write the code once, as a Function, not a Sub, in a standard module,
and call it from a function expression placed directly in the event property
of each control. For example, you could have this function defined in a
standard module:

'------ start of code ------
Public Function ZoomControl()

RunCommand acCmdZoomBox

End Function
'------ end of code ------

Then you could select all the text boxes on your form, open their combined
property sheet, and set the On Dbl Click property to:

=ZoomControl()
 
A

Arvin Meyer [MVP]

I would do it like this:

Function Zoom()
DoCmd.RunCommand acCmdZoomBox
End Function

Now, in the form's design view, I'd select all the text boxes, or just the
ones your want, and open the property sheet. Then I'd add:

=Zoom()

to the Double-click event. Now every textbox, or just the ones you want,
will zoom on the Double-click event.
 
A

alex

I would do it like this:

Function Zoom()
    DoCmd.RunCommand acCmdZoomBox
End Function

Now, in the form's design view, I'd select all the text boxes, or just the
ones your want, and open the property sheet. Then I'd add:

=Zoom()

to the Double-click event. Now every textbox, or just the ones you want,
will zoom on the Double-click event.
--
Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmvp.com













- Show quoted text -

Worked perfect guys; Thanks a lot!
alex
 

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

Similar Threads


Top