"Call ControlName_DblClick" -- does not work

T

Tom

I have a 21 textboxes that opens up a popup form via a double-click. I then
enter text in the popup form... which -- when closed -- passes the
information into the textbox.

Currently, the textboxes (controlnames = Comment1 to Comment21) are visible
but I don't show all of the text (it's only about 1 inch wide).

So, here's what I'm hoping to do...
- hide the textboxes that call the popup via double-click
- add a double-click event to their adjacent combo box (controlnames =
Frame1 to Frame21). The combos will remain visible.
- the combo's double-click will "execute" (double-click) the hidden
textboxes
- hence it will appear that the combo boxes bring up the popup

Here's what I have done so far:

- added "=CallPopUp()" to all of the 21 combos "Double-Click" (in the
properties window)
- added the function below... Frame1 to Frame9 have a controlname length of
6; Frame10 to 21 have a length of 7.
- so, when double-clicking on Frame1 to Frame 9, I get the message "Hello -
1"; otherwise I get "Hello - 2".

Okay, here's what I need some help with:
- I need to replace the "Hello" message with some code that will
"doubleclick" let's say Comment1. (I'll deal with the proper comment box
later).
- I replaced the msgbox with "Call Comment1_DblClick"... that didn't seem to
work.

So my question, how do I properly "call" the double-click of another
control?

Thanks,
Tom



==============================
Function CallPopUp() As Boolean

Dim ctl As Control
Dim FieldName As String, FieldName1 As String

Set ctl = Screen.ActiveControl
If Len(ctl.Name) = 6 Then
FieldName1 = "Comment" & Right(ctl.Name, 1)
MsgBox "Hello - 1"
'Comment1_DblClick

ElseIf Len(ctl.Name) = 7 Then
FieldName1 = "Comment" & Right(ctl.Name, 2)
MsgBox "Hello - 2"

End If

Set ctl = Nothing

End Function
==============================
 
A

Andrew Backer

Well, first thing I would think of is to move the code out of the
double click method and into it's own "Show Popup" function. Since
it's called in more than one place, this is what you should do.

I was able to get it work just fine by calling it like this :

Dim setcancel As Integer
Call LabelField_DblClick(setcancel)

The double click stored prodcedure takes a integer cancel button, but
you have to pass it too.

Hope this helps,
Andrew Backer
 
T

Tom

Andrew:

Thanks for the prompt reply... not sure if I'm following you all the way...
quick recap:

a. control "Comment1" has "=ZoomBox(Screen.ActiveControl)" in its event
property (Double-click)
b. control "Frame1" has "=CallPopUp()" in its event property (double-click)
c. currently, when performing step a), the popup is opened
d. control in step a, however, must be executed by performing step b).
That'll allow me to hide the control Comment1.

I added the 2 lines (below) to the CallPopUp function. Now, when
performing step b) -- which should execute step a) -- I get the following
error message:

Compile Error. Sub or Function not defined. The line "Call
Comment1_DblClick" is highlighted.

What am I missing?

Tom


code modification... based on your suggestions:

....
....
Dim setcancel As Integer
Set ctl = Screen.ActiveControl
If Len(ctl.Name) = 6 Then
FieldName1 = "Comment" & Right(ctl.Name, 1)
MsgBox "Hello there 1"
Call Comment1_DblClick(setcancel)
....
....
 
A

Andrew Backer

Ok, so you have an expression in the double click event, which means
you do not actually have any *code* in the module for it, which is why
it can't find it. You actually have the OnClick event set, or
something like that, and I won't pretent to toally understand it...

You might be able to do something like this, which reads the command
you have assigned to the control and executes it :

Dim cmd As String
cmd = Me.Label.OnDblClick
debug.print cmd ' -- just to see :)
cmd = Replace(cmd, "=", "")
Call Eval(cmd)
From what you are doing it looks like it will be a little more tricky,
since you are trying to pass a reference to the active control. I am
having trouble getting ActiveControl to return a normal control, its
behaving wierd for me. You might need to call a .SetFocus on the
control you want. There may be a way to fire the event directly, but I
am not aware of it.

Can you just call the function directly, " zoombox( me.control1 ) "
rather than trying to execute the doubleclick event? Perhaps you can
eval() that?

HTH, again,
Andrew Backer
 
T

Tom

Andrew:

sorry... still not sure about this...

Sometimes, 'pictures are worth 1000 words'... I posted a small sample file
(DblClick.zip) at the following site

http://tombock2004.i8.com/Test.i8.com/Test

If you feel comfortable downloading the file, the "notes" on frmSurvey
(default) should describe the process much better.

Again, thousand thanks in advance!

Tom

--
 
C

Carl Rapson

What you're missing is the actual Sub named "Comment1_DblClick", which must
exist for you to be able to call it. Another alternative to what Andrew is
suggesting would be to add VBA code to handle the DblClick event for each
text box. You can do this by changing the On Dbl Click property for each
text box to [Event Procedure], click on the "..." box next to the property,
and add "ZoomBox Screen.ActiveControl" to the resulting DblClick event. Save
the modified code, and now you should be able to use "Call
Comment1_DblClick" to execute the dbl click event for Comment1 (for
example).

HTH,

Carl Rapson
 
A

Andrew Backer

That is a pretty nice little thing sample there, I commend you.

Now... onto the solution. This is the new code in the CallPopup()
function. I just take the word "Frame" with the word "Comment" to get
the other control, and then reference that control by name in the
form's control collection. This works when the control is visible *or*
hidden, which might otherwise be a problem since you can't SetFocus to
a hidden control.

Dim strControl As String
Set ctl = Screen.ActiveControl
strControl = Replace(ctl.Name, "Frame", "Comment")
Call ZoomBox(Me.Controls.Item(strControl))

In opinion. I think you should look at passing OpenArgs to the form
you are opening, rather than referencing a control on another form.
Ie, pass the ID of the row you want to edit via DoCmd.OpenForm
"...",,,,"IdNumber" and then retrieve/populate/save inside the subform.
This is what I do when I, I have edit dialogs for individual items to
which I pass the id # and they do the rest of the work, leaving me to
just requery the form. I am worried about the flexibility of this way.
In the end you would call "ZoomComment(3)" etc.

Option 2 is to look into using the .Tag field of your controls. You
could use this to either indicate the ID, or possibly the control name
you want to reference. It would save you from having to name controls
in a certain way (ie frame2/comment2, etc). Look under
'properties->other' at the bottom.

' assuming that the activcontrol contains a TagField referencing a
comment :
ZoomBox( Me.Controls.Item( ctl.Tag ) )

HTH,
Andrew Backer
gmail://awbacker
 
T

Tom

Andrew:

Wow... that is absolutely BRILLIANT!!! I'm very impressed by your
solution.

....dbl-clicking any combo will pop up the associated textboxes... it stores
the text... AND I can hide the textboxes.

I now truly appears that the combo call the popup form. Again, thousand
thanks!
 
A

Andrew Backer

Thank yourself, though I do appreciate it :) The best thing was your
sample DB. You took some time to prepare it, and it is really what
made it possible to understand properly.

Much luck,
Andrew
 

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