Wrong event triggered on listbox_Click/Enter/Got Focus

P

Patti

I have a list box (LB1) that displays a list of clients. I have
another list box (LB2) that displays a list of phone calls. I want to
auto-select the first row in LB2 after the user selects a client in
LB1.

Here is my code:

Private Sub lstClients_AfterUpdate()

Me.lstCallLog.Requery
Me.lstCallLog.Selected(0) = True
End Sub


The problem is that when I click LB2, the LB1_AfterUpdate is
triggered. I have verified this by putting in a breakpoint in the
LB1_AfterUpdate event. The Click event, On Enter, On Got Focus, and
On Mouse Down events never fire for LB2! WHY???

The offending code is Me.lstCallLog.Selected(0) = True. When I
comment this out, the LB2_Click event works again, but that completely
defeats my purpose.

For testing purposes I created a new DB, and there is only one form in
my DB, and this is the ONLY code anywhere in the DB. Tables are
linked to a back end DB. Ultimately I want to limit the phone call
list to calls made to the client selected in LB1, but for testing
purposes I took out that criteria. LB2 now lists ALL phone calls in
tblPhoneCall.

Any help would be greatly appreciated!

Patti
 
D

dan artuso

Hi,
Are you sure the events correspond to the names of your list boxes?
You refer to them as LB1, LB2 but your event code shows the name
lstClients, not LB1.
I assume lstCallLog is really LB2?

Dan Artuso, MVP
 
P

Patti

Yes, sorry about that. My list boxes are named lstClients and
lstCallLog. I used LB1 and LB2 just for discussion, but it seems that
only confused things! :)

Thanks,

Patti
 
D

dan artuso

Hi,
Okay, you're saying that when you click on lstCallLog, the lstClient
AfterUpdate fires?
There must be some code in the lstCallLog click event, no?

You've shown code for lstClients, show the code for lstCallLog as well. In
fact,
post *all* relevant code for both list boxes and maybe we can solve this.

Dan Artuso, MVP
 
P

Patti

Dan,

Many thanks for replying - I do greatly appreciate it.

Yes, when I click on lstCallLog, the lstClient_AfterUpdate fires.
There is no code in lstCallLog. The only code in the *entire* DB is
below:

****** Begin Code ******
Option Compare Database

Private Sub lstClients_AfterUpdate()

Me.lstCallLog.Requery
Me.lstCallLog.Selected(0) = True

End Sub
****** End Code ******


That is it. Honest. I created a new DB just so that I could test
this, and the only thing in the DB is this form, and this is the only
code in the form.

However, after much digging, I found a solution. If you are
interested, it is on this thread:
http://groups.google.com/groups?hl=...g&selm=ueoEcJWTCHA.2584%40tkmsftngp13&rnum=18

If that link doesn't work, look up the subject "Selected property of
ListBox and SetFocus Requirement?" It is a correspondence between Ken
Snell and Dirk Goldgar in August 2002. Dirk posted the code that
solved my problem, and it is this:

Instead of using Me.lstCallLog.Selected(0) = True, I use this code:

****** Begin Code ******
With Me.lstCallLog
.Value = .ItemData(-(.ColumnHeads))
End With
****** End Code ******

I do not know why Me.lstCallLog.Selected(0) = True doesn't work, but
it doesn't!!! This has been nagging me for months, and I am glad that
I finally found a solution.

Again, many thanks for your help! :)

Patti
 

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