Issue 114946 - "when receiving focus" event calls assigned macro infinite times
Summary: "when receiving focus" event calls assigned macro infinite times
Alias: None
Product: Base
Classification: Application
Component: code (show other issues)
Version: OOO320m18
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Depends on:
Reported: 2010-10-05 22:29 UTC by jasktron
Modified: 2013-01-29 21:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Note You need to log in before you can comment on or make changes to this issue.
Description jasktron 2010-10-05 22:29:39 UTC
Focusing controls in a Base form set with a "when receiving focus" event causes
infinite calls of assigned macro. This problem was encountered both under Linux
and Windows systems. On the other hand, as expected, a control set with "when
losing focus event" calls the assigned macro only once.
Comment 1 Frank Schönheit 2010-10-06 12:04:20 UTC
somehow I bet that within your macro code, you open a modal dialog box, or
something like this ...

The problem usually is that your macro does something which steals the focus
from the control, and when the focus is implicitly given back (e.g. because the
dialog is closed), then this of course triggers a new event ...
Comment 2 jasktron 2010-10-06 19:38:31 UTC
The problem in detail is the following (ooo Base):

1) place a text control (or a listbox...) in a form, assign the following sample
macro to the "when receiving focus" event:

Sub Test
msgbox "Test!"
End Sub

2) when the control receive focus, the "Test!" alert repeats infinite times and
hangs the application
Comment 3 jasktron 2010-10-06 19:54:11 UTC
The macro really I used is the following:

Sub sqlcats
  Dim current_IDcatp as Integer
  Dim current_IDcats as Integer
  formdoc = ThisComponent
  oform = formdoc.DrawPage.Forms.getByName("form1")
  osubform = oform.getByName("subform3")
  ogrid = osubform.getByName("attrcat_grid")
  octl = ogrid.getByName("catp")
  current_IDcatp = octl.BoundField.value
  octl = ogrid.getByName("cats")
  octl.ListSource = Array("SELECT ""label"", ""IDcats"" FROM ""cat-sec_tbl"" 
WHERE ""cat-sec_tbl"".""IDcatp"" = " & current_IDcatp)
End Sub

Does this macro steal also the focus causing the event re-triggering? When the
listbox control is focused, the internal content flickers.
Comment 4 jasktron 2010-10-06 20:14:12 UTC
The strangeness is that after moving the focus with the arrow keys between the
fileds of subform grid, the content of listbox sometimes returns normal and
sometimes doesn't.
Comment 5 Frank Schönheit 2010-11-22 20:44:57 UTC
this issue slipped my attention for a while - sorry!

No, your second macro does not contain any obvious reasons for an infinite event
calling. Well, the refreshing of the list box might be a not-so-obvious one ...

To be sure to investigate the right thing: Do you mind creating a small,
self-contained database document with your macro, which shows the problem?

I think one thing we could do is to disallow nested event firing - that is, if
the first event is still running, subsequent requests to fire the same event
should be ignored. This could fix the problem - but I'd like to see the bug in
action before embarking on this.