double click events

R

Roddy

I have 6 text field with double click events. I want to use on control to
execute all 6 how do i do this
 
R

Robert Morley

I'm not sure exactly what you mean by using one control to execute all 6
events. Do you mean something like a command button that manually runs all
6 (instead of having to double-click on each one separately)? Or do you
mean that the event is the same for all 6 and you want one routine to handle
them all?

If it's the first one, you would set up your command button to do something
like this:
Dim Cancel As Integer

Cancel = False
MyField1_DblClick Cancel
MyField2_DblClick Cancel
...etc.

Note that you can ignore the return value of Cancel if you don't care if any
of the events were cancelled (or if you have no code in the events that
COULD cancel them), but you still have to pass something to the event.

If you meant the latter one, having one event for all 6, then you can do it
one of two ways, depending again if you need to track or change the Cancel
value. The first method is to simply set the On Double Click property to
the form to "=MySixFieldRoutine()" (without the quotes). To my knowledge,
you cannot pass or track the Cancel status this way, though.

If you need to track the Cancel value, then you would set up your own
routine as a public sub in the form, and have each of the Double Click
events call your routine:

Private Sub MyField1_DblClick(Cancel As Integer)
MySixFieldRoutine Cancel
End Sub



Rob
 
R

Robert Morley

value. The first method is to simply set the On Double Click property to
the form to "=MySixFieldRoutine()" (without the quotes). To my knowledge,

Woops, bad wording in what I said. That should've read "set the On Double
Click property for each of the text fields to". Don't know what I thought I
was saying. :)


Rob
 
R

Roddy

yes a command button to run all 6 seperately or better yet from form click
event
thanks Rob.
 
R

Roddy

when i use the first method the text fields do not recieve focus. I tried
setfocus and go to control but it does not function need help

Dim Cancel As Integer

Cancel = False
MyField1.setfocus_DblClick Cancel
docmd.gotocontrol MyField2_DblClick Cancel
...etc.
 
R

Robert Morley

Why do the fields need to have the focus? Maybe if you explained a bit more
about what it is you're trying to do, we could suggest a better way.

As to SetFocus, you would use it like this:

MyField1.SetFocus
MyField1_DblClick Cancel
MyField2.SetFocus
MyField2_DblClick Cancel
etc.



Rob
 
R

Roddy

each text field runs a total query from different tables. When i doubleclick
each text field the query runs ok.This recent code you sent runs the first
text double click event but stops or shuts down the form before running the
next text doubleclick event. I hope i am explaining this clearly bear with
me. thanks
 
R

Robert Morley

That sounds like something in the event is setting Cancel to True, or is
otherwise cancelling the event somehow before the next line gets to run.
I'm not sure why that would be...can you send a sample of the code that
would be in the first DblClick event?


Rob
 
R

Roddy

Private Sub Form_DblClick(Cancel As Integer)
On Error GoTo Err_Command312_Click

Cancel = False


TOT_PURCHASE.SetFocus
TOT_PURCHASE_DblClick (Cancel)

TOT_PURCHASE2_.SetFocus
TOT_PURCHASE2_DblClick (Cancel)

TOT_COLLECTED.SetFocus
TOT_COLLECTED_DblClick (Cancel)

TOT_COLLECTED2.SetFocus
TOT_COLLECTED2_DblClick (Cancel)

Exit_Command312_Click:
Exit Sub

Err_Command312_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Command312_Click
End Sub
 
D

Douglas J. Steele

I suspect Robert wanted to see what code was in TOT_PURCHASE_DblClick,
TOT_PURCHASE2_DblClick, etc.

By the way, your syntax is technically incorrect.

When you're invoking a sub, either leave off the parentheses:

TOT_PURCHASE_DblClick Cancel

or use the Call statement:

Call TOT_PURCHASE_DblClick (Cancel)

What you're doing will work if you've only got 1 parameter, but if your sub
is expecting more than 1 parameter, it will not work. In actual fact,
putting the parenthesis around Cancel without using the Call keyword means
you're passing the parameter ByVal, not ByRef. This means that if the value
of the parameter is changed in the routine being called, you will NOT get
that value in the routine that called the routine. Perhaps the following
example will help.

I've got a routine named "Called", the sole purpose of which is to change
the value of the parameter being passed:

Sub Called(TextString As String)
TextString = "Passed from Called"
End Sub

If I run this code:

Dim strText As String

strText = "Passing this to Called"

Debug.Print "strText before call: " & strText
Called strText
Debug.Print "strText after call: " & strText

I get the following in the Debug window:

strText before call: Passing this to Called
strText after call: Passed from Called

However, if I use parentheses when calling the routine

Dim strText As String

strText = "Passing this to Called"
Debug.Print "strText before call: " & strText
Called (strText)
Debug.Print "strText after call: " & strText

I get:

strText before call: Passing this to Called
strText after call: Passing this to Called
 

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