RE: ListIndex property is reset if I SetFocus

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
    ... Doug Steele, Microsoft Access MVP ... 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: resize-ereignis
    ... Controls noch viel einfacher. ... Private WithEvents LBox As ListBox ... Private Sub InitControls() ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: filling userform listbox
    ... Here is a method that uses 1 ListBox and a Label on a User Form. ... don't think you need a second ListBox if it is only to display data. ... TextColumn controls which column ... Private Sub UserForm_Activate ...
    (microsoft.public.excel.programming)
  • 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)