What is causing this OnClick event?
In an earlier thread I recounted a problem I was having, but it took a
while to reduce the problem to it's basic components and the issue
became somewhat confused in reaching that point. I hope you will
excuse me for bringing it up again but this issue is very frustrating.
I created a new form in a brand new (Access 2003) database. This
example does nothing useful other than to illustrate the problem.
I've explained what I want to do in my real application at the bottom
of this post.
My problem is that, if I click on List2, it generates an OnClick event
in List1 which prevents me from selecting any item in List2.
The form has no record source; default view is 'Single Form'; record
selectors, scroll bars, naigation bars etc are off.
The form has only three controls:
- List1 is extended-multi-select with RowSource of "Line 1";"Line
2";"Line 3";"Line 4"
- List2 has no multi-select. The RowSourceType is Value List and the
list is empty.
- cmdButton is a command button.
Here is the entire code:
Option Compare Database
Private Sub cmdButton_Click()
MsgBox ("OnClick - Button")
Private Sub List2_Click()
MsgBox ("OnClick - List 2")
Private Sub List1_Click()
Dim i As Integer
Dim strRowSource As String
Const QT = """"
MsgBox ("OnClick - List 1")
For i = 0 To Me.List1.ListCount - 1
If Me.List1.Selected(i) Then
If Len(strRowSource) > 0 Then
strRowSource = strRowSource & ";"
strRowSource = strRowSource & QT & Me.List1.Column(0, i) & QT
Me.List2.RowSource = strRowSource
Me.List2.Selected(0) = True '<############ this is the problem
If I remove the second-last line the form works OK, but not quite the
way I want. But why would this line cause a click on List2 or the
cmdButton to generate an OnClick event on List1?
A possible clue? If Record Selectors are on, selecting this 'record'
allows List2 and cmdButton to work, until a new selection is made from
List1 at which point it locks up again.
For background information, in my real-life application List1 is a
list of types of events. List2 is a list of events of that type and I
have a subform which lists all the people attending the event selected
in List2. However, everytime I select an event (List2) it generates
an OnClick event on List1 which rebuilds List2 and automatically
selects the top item in the list. It is therefore impossible to
select an event from List2.