RE: ListIndex property is reset if I SetFocus
- From: Jon Ley <JonLey@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Nov 2007 03:49:00 -0800
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.
- Follow-Ups:
- RE: ListIndex property is reset if I SetFocus
- From: Dale Fye
- Re: ListIndex property is reset if I SetFocus
- From: Douglas J. Steele
- RE: ListIndex property is reset if I SetFocus
- Prev by Date: Re: Check users logged on
- Next by Date: Printing single record
- Previous by thread: Re: Check users logged on
- Next by thread: Re: ListIndex property is reset if I SetFocus
- Index(es):
Relevant Pages
|