Coercing ListBox.ListIndex?

P

(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")
 
P

(PeteCresswell)

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...
 
S

Stephen Lebans

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) said:
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...
 
P

(PeteCresswell)

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.
 
R

RoyVidar

(PeteCresswell) said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top