What's up with focus here

  • Thread starter Thread starter Tony Vrolyk
  • Start date Start date
T

Tony Vrolyk

Wondering why when using the code below the focus jumps back to txtSSN and I
can't click on any other control. If I uncomment the
"Me.lstParticipants.SetFocus" I get an error 2110 - Can't move focus.

Private Sub txtNewSSN_AfterUpdate()

If Not IsNull(Me.txtNewSSN) Then
Me.lstParticipants.RowSource = "Something"
If Me.lstParticipants.ListCount = 1 Then
Me.lstParticipants.Selected(0) = True
' Me.lstParticipants.SetFocus
Me.cmdSave.Enabled = True
Else
Me.cmdSave.Enabled = False
End If

End If


Thanks
Tony
 
You're sure it is AfterUpdate? (You can not change the focus from
BeforeUpdate.) If so, here's what I'd check.

- is the listbox enabled?

- does it have any GotFocus nasties?

- is it something to do with changing the rowsource? (I'd comment-out that
line to see if that changes things. Change the "= 1" temporarily in order to
test both branches.)

HTH,
TC
 
Yes this is in the AfterUpdated event. The only code behind the form is on
Open, behind two buttons (cancel and save) and the code below.

If I comment out the rowsource line I still get the setfocus error but
afterwards I can move to other controls including the listbox. Of course the
rowsource line is pretty key to this working so I am not sure how to work
around it. BTW the rowsource should only be returning a single row or none
at all.

I put in some msgboxs to get feedback on the "If...listcount = 1" and it
appears to be working correctly.

It is as if the AfterUpdate is firing each time I leave the txtNewSSN even
when the data has not changed. I have since given up and used the work
around, though I am still curious why this was happening.

Tony
 
All I can think of is that maybe setting the rowsource of the listbox is
causing the form to recalculate. This might make the focus try to move back
to the first enterable control in tab order. It might be interesting to make
the textbox the first control in tab order & see if it still happens. (But
it probably would, because if that >is< the cause, the focus would probably
try to leave & then re-enter the listbox.)

Sorry I can't help further :-(

TC
 
Back
Top