Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Well ... starting feel pretty dumb right about now.
Basically, I added a combobox to an access form, named it newCombo and bound it to a recordset.
Then I went into the code for Private Sub Form_Load() and am looking through the autocomplete list of methods and properties.
So, I type newCombo. and if I look through the list, I cant find .selected, it doesn't have .selectedIndex, it does have .listIndex but I cant seem to use it.
If I try to use them anyway, they throw errors.
Surely there is a way to do this, but I just cant seem to find it.
Any more help here would be great.
Last edited by Stryker; May 9th, 2005 at 09:01 AM.
Reason: Forgot to mention
Apologies - yes I was looking at a listbox not a combo box (duuh).
Listindex (as RobDog has posted) should work fine, in normal instances, however you've bound it so this may affect things. As I don't use bound controls (hate 'em) I cannot advise on this; except to say you should experiment with as many different ways/methods as you can then you can decide which is better.
Uh... second thought - if its bound why are you trying to change the selected item... surely it updates as you change records?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Apologies - yes I was looking at a listbox not a combo box (duuh).
Listindex (as RobDog has posted) should work fine, in normal instances, however you've bound it so this may affect things. As I don't use bound controls (hate 'em) I cannot advise on this; except to say you should experiment with as many different ways/methods as you can then you can decide which is better.
Uh... second thought - if its bound why are you trying to change the selected item... surely it updates as you change records?
Good point Ecniv. If its a bound control you can navigate the rs so its displaying the record or item you desire.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I just had the same problem in Access 2007. My problem turned out to be that I did not setfocus to the control I was changing.
I am populating two list or combo boxes with the same info. After you have chosen one I want to programmatically choose the next one to avoid time wasted for the user. Neither worked. Most of MS documents I came across tonight said the Listindex was "Read Only" only 2 stated it was read/write.
1. In any case my problem was I did not setfocus to the control I was changing. While others I have populated with info I did not have to setfocus too.
2. Just in case, for those that do not know. You have to make sure the item is selected and not just scrolling to it.
With my number of years experience I still dont know the pattern or rule for setfocus. Any documentation or rules as to when you have to and should setfocus? Why I ask is I populate a number of textboxes during this code and setfocus never came to mind being the other objects filled in.
Using Access 2007 I just did this for a combobox to preselect a certain value (Values are from a query):
Code:
Me.comboIssue_Status = 1
Remember if the query results are sorted then it may not be clear what the index of the item is. I found it easier to select the item, then press any button having set a breakpoint and check the value of the combobox which in my case was 1 (which was the 3rd item in the list as the list was sorted)