Determine Source Label of DblClick

PeregrinTook

Registered User.
Local time
Today, 22:28
Joined
Aug 1, 2006
Messages
15
Hi all,

Just wondering if anyone knows if this is possible please - I can't find anything helpful on the net so any tips would be much appreciated...

I'm making a form which allows the creation of letter templates, with functionality for users to double click a query field name (from a list in a sidebar) and have that field name entered (in the format <BusinessAddress1>) on a master letter template form.

The list of available field names in the sidebar are all labels, and each currently has a DblClick event like this:

Code:
Private Sub BusinessAddress1_DblClick(Cancel As Integer)
    Call InsertFieldName("BusinessAddress1")
End Sub

Where InsertFieldName is a function to enter the text string passed to it into the master letter template.

There are now many query fields available on each sidebar list, and the number of available queries (and therefore sidebar lists) is growing rapidly.

The above method was ok for each label when there were only a few, but the more I add the more sure I am there must be an easier and neater way!

So my question then is this.

Is there a form-level way to determine the name of the label that was double-clicked, then just pass that name straight into the InsertFieldName function - thus removing the need to hard-code a text string to pass for each individual label's DblClick event?

I hope I've given a clear enough picture of the problem, and any help is much appreciated I can assure you!

Many thanks
PT
 
Screen.ActiveControl

So:

Call InsertFieldName(Screen.ActiveControl)
 
Hi Bob,

Many thanks for the reply.

Did you mean to use Screen.ActiveControl still within a private sub for each label like this?

Code:
Private Sub BusinessAddress1_DblClick(Cancel As Integer)
    Call InsertFieldName(Screen.ActiveControl)
End Sub

If so, I get the following error:

"Runtime error 2474: The expression you entered requires the control to be in the active window"

I think this is because it's a label rather than textbox, therefore doesn't actually have focus to be the 'active control'...

But perhaps you were meaning to use Call InsertFieldName(Screen.ActiveControl) at form level instead and that's what's wrong? I tried inserting that into the Form's double click event but it didn't get called when I double clicked the label...

Again any suggestions much appreciated please!
Many thanks
PT

ps Sorry for posting in more than one forum - I just thought it'd give better odds of a reply but I suspect now I've fallen foul of some posting etiquette here... :o I'll just stick to this forum!
 
Sorry, I thought you were talking about text boxes, not labels. Text boxes can be an active control. Labels cannot so I think as LPurvis mentioned over in Utter Access, you may be stuck with filling in the name for the parameter anyway.
 
But perhaps you were meaning to use Call InsertFieldName(Screen.ActiveControl) at form level instead and that's what's wrong? I tried inserting that into the Form's double click event but it didn't get called when I double clicked the label...

You have to put SOME call to something in the double click event of the control or else Access isn't going to know that you double-clicked on that item.
 

Users who are viewing this thread

Back
Top Bottom