PC Review


Reply
Thread Tools Rate Thread

Coercing ListBox.ListIndex?

 
 
(PeteCresswell)
Guest
Posts: n/a
 
      10th Dec 2006
Seems like I've done it before - and Help seems to indicates it's possible from
VBA, but on this one it's throwing an error:
--------------------------------------------------------------
?[forms]![frmDeal]![lstTrancheTradeDates].BoundColumn
0

?[forms]![frmDeal]![lstTrancheTradeDates].listcount
1

[forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
("Error 7777 You've used the listindex property incorrectly")
--------------------------------------------------------------
--
PeteCresswell
 
Reply With Quote
 
 
 
 
(PeteCresswell)
Guest
Posts: n/a
 
      10th Dec 2006
Per (PeteCresswell):
>Seems like I've done it before - and Help seems to indicates it's possible from
>VBA, but on this one it's throwing an error:
>--------------------------------------------------------------
>?[forms]![frmDeal]![lstTrancheTradeDates].BoundColumn
> 0
>
>?[forms]![frmDeal]![lstTrancheTradeDates].listcount
> 1
>
>[forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
>("Error 7777 You've used the listindex property incorrectly")
>--------------------------------------------------------------


Reading/taking the Help example more literally, I can work around it with:
-------------------
[forms]![frmDeal]![lstTrancheTradeDates].Setfocus
[forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
-------------------

But that doesn't get it for this particular app because the listbox is
buried in a page on a tab control - and if the right page isn't already
selected, the .Setfocus traps out. I can't coerce the page because that
would create consternation in the user.

It *Still* seems like I've done this in the past with no problems and no .Select
beforehand...
--
PeteCresswell
 
Reply With Quote
 
Stephen Lebans
Guest
Posts: n/a
 
      10th Dec 2006
Hi Pete,
the control must have the focus when you set the ListIndex prop.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


"(PeteCresswell)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Per (PeteCresswell):
>>Seems like I've done it before - and Help seems to indicates it's possible
>>from
>>VBA, but on this one it's throwing an error:
>>--------------------------------------------------------------
>>?[forms]![frmDeal]![lstTrancheTradeDates].BoundColumn
>> 0
>>
>>?[forms]![frmDeal]![lstTrancheTradeDates].listcount
>> 1
>>
>>[forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
>>("Error 7777 You've used the listindex property incorrectly")
>>--------------------------------------------------------------

>
> Reading/taking the Help example more literally, I can work around it with:
> -------------------
> [forms]![frmDeal]![lstTrancheTradeDates].Setfocus
> [forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
> -------------------
>
> But that doesn't get it for this particular app because the listbox is
> buried in a page on a tab control - and if the right page isn't already
> selected, the .Setfocus traps out. I can't coerce the page because that
> would create consternation in the user.
>
> It *Still* seems like I've done this in the past with no problems and no
> .Select
> beforehand...
> --
> PeteCresswell



 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      10th Dec 2006
Per Stephen Lebans:
>Hi Pete,
>the control must have the focus when you set the ListIndex prop.


I guess that settles that....

Must've been accidentally selected in my previous apps.

I coded a workaround - checking the TabControl.Value to see if the box is
visible and then squirreling away a pointer to .ActiveControl before setting
focus and then returning focus to the prior control.... and then coding a
Change() event for the tab control to do what needed tb done if/when the user
decided to open up that tab.

Great stuff!.... If it was too simple, nobody's pay us to do it.... -)

Thanks.

--
PeteCresswell
 
Reply With Quote
 
RoyVidar
Guest
Posts: n/a
 
      10th Dec 2006
"(PeteCresswell)" <(E-Mail Removed)> wrote in message
<(E-Mail Removed)>:
> Seems like I've done it before - and Help seems to indicates it's
> possible from VBA, but on this one it's throwing an error:
> --------------------------------------------------------------
> ?[forms]![frmDeal]![lstTrancheTradeDates].BoundColumn
> 0
>
> ?[forms]![frmDeal]![lstTrancheTradeDates].listcount
> 1
>
> [forms]![frmDeal]![lstTrancheTradeDates].listindex = 0
> ("Error 7777 You've used the listindex property incorrectly")
> --------------------------------------------------------------


As stated elsethreads, .ListIndex needs the control to have focus.
But, it seems you're using .BoundColumn = 0, in that case .Value =
..ListCount, which means

[forms]![frmDeal]![lstTrancheTradeDates].Value = 0

should work.

Else, if you've bound it to the first column, I think this kludge
should work (without column heads)

[forms]![frmDeal]![lstTrancheTradeDates].Value = _
[forms]![frmDeal]![lstTrancheTradeDates].Column(0, 0)

--
Roy-Vidar


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox.listindex FR Microsoft Access VBA Modules 2 2nd Oct 2008 08:13 PM
nothing selected in listbox, but listindex <> -1 steve Microsoft Excel Programming 2 8th Mar 2008 07:49 PM
ListBox and ListIndex mtm4300 via OfficeKB.com Microsoft Excel Programming 2 5th Apr 2006 05:56 PM
listbox listindex problem jacob Microsoft Excel Programming 2 25th Aug 2004 08:46 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Microsoft Excel Programming 0 22nd Oct 2003 12:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:37 AM.