Re: ListIndex property is reset if I SetFocus



Can you not just set focus back to the list box then?

Me.lstScores.SetFocus

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jon Ley" <JonLey@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5D282963-E419-4D99-8B70-745209A7C926@xxxxxxxxxxxxxxxx
Dale,

No, the list box is not multi-select, and I am using the .Column property.
The code is:

*** Start of code ***
Private Sub lstScores_AfterUpdate()

If lstScores.ListIndex < 0 Then
Exit Sub
End If
cboCategoryID = lstScores.Column(0)
Call cboCategoryID_AfterUpdate 'xxxx
cboSectionID = lstScores.Column(1)
Call cboSectionID_AfterUpdate
cboItemID = lstScores.Column(2)
Call cboItemID_AfterUpdate
cboScore = lstScores.Column(4)
cboAction = lstScores.Column(6)
txtComments = DLookup("Comment", "tmptblAuditDetails", _
"AuditID = " & txtAuditID & " And " & _
"ItemID = " & cboItemID)

End Sub
*** End of code ***

The line that is commented 'xxxx is where the SetFocus gets called. All
attempts to get at any .Column(x) entries after that point return Null.
However if I break the code immediately after 'xxxx and reset the focus
to
the listbox, the ListIndex value is restored to what I would expect it to
be
and all the subsequent .Column(x) calls work fine.

Thanks,

Jon.

"Dale Fye" wrote:

Can you post your code? If your listbox is not multi-select, you really
shouldn't need to refer to the controls listindex. My guess is that you
are
doing something like:

me.txt_First_Name = me.lst.column(1, me.lst.listindex)
me.txt_Last_Name = me.lst.column(2, me.lst.listindex)

since the row element of this is optional, you can probably just replace
this with:

me.txt_First_Name = me.lst.column(1)
me.txt_Last_Name = me.lst.column(2)

HTH
Dale


--
Don''t forget to rate the post if it was helpful!

Email address is not valid.
Please reply to newsgroup only.


"Jon Ley" wrote:

I have a form with a listbox which has AfterUpdate code behind it. The
code
collects data from various columns in the list box to populate other
controls
on the form (ready for the user to edit) and sets the focus to another
control. The SetFocus command is called before the other controls have
finished being populated, but as soon as the SetFocus is called, the
ListIndex property of the ListBox is reset to -1 and I cannot retrieve
any
further information from the ListBox columns (all return Null).

This code has worked fine for ages in Access 2002, but fails when I
open the
same database in 2007. Also, if I break the code and set the focus back
to
the ListBox, the ListIndex property is restored to its correct value
and I
can continue to populate the remaining controls.


.



Relevant Pages

  • Re: ListIndex property is reset if I SetFocus
    ... I have several large database systems in use throughout our ... shouldn't need to refer to the controls listindex. ... ListIndex property of the ListBox is reset to -1 and I cannot retrieve ...
    (microsoft.public.access.formscoding)
  • RE: ListIndex property is reset if I SetFocus
    ... Private Sub lstScores_AfterUpdate ... shouldn't need to refer to the controls listindex. ... ListIndex property of the ListBox is reset to -1 and I cannot retrieve any ...
    (microsoft.public.access.formscoding)
  • Re: How To Handle Empty Array
    ... From Help file for ListBox as an example, other controls are similar-- ... A ListBox control displays a list of items from which the user can select one or more. ... the ListIndex property value is -1. ... The first item in the list is ListIndex 0, and the value of the ListCount property is always one more than the largest ListIndex value. ...
    (microsoft.public.vb.general.discussion)
  • Re: Q: Owner Drawn LB with Panels for the Items
    ... TextBox control is slapped on top of the ListBox to enable in-place editing. ... individual controls as the list items. ... If all the controls are the same width as a panel and you ... > ControlPaint and it only has Draw... ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • RE: button that locks fields
    ... Dave Hargis, Microsoft Access MVP ... with regards to auto number issue. ... Forms have controls and some of those controls can be bound to ...
    (microsoft.public.access.gettingstarted)