Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set listindex 2

Status
Not open for further replies.

ricm9

Programmer
Jun 7, 2002
20
US
For some reason, when I try to set the listindex property of a combobox, I get an error saying I have used the listindex property incorrectly.

Any idea why I get this?
 
The problem is the the listindex property of a combobox is READ-ONLY. It is there for you to extract the value of the selection in the combobox but not to set it. It is a number starting at 0 for the first selection through the number of selections(n-1) in the Row Source property. Check out the ACCESS Help for ListIndex property of a combobox. The specifics are all there.

Hope this helps you. Bob Scriver
 
Had the same problem with a listbox. I know in the past I have sent sendkeys syntax to a listbox, but I think it's best to stay away from senkeys, as if you do not control where they go, all fun lets loose. Regards
 
But I see several posts in these forums that show code to set the listindex property. As I look in the help files, I see this example:

To set the ListIndex property value, you can use the following:
Forms(formname).Controls(controlname).ListIndex = index

 
Now if you are trying to set the selection of a Combobox you can do that by just assigning the value to it if the Bound Column value is something that you would know.
Example: If you want the ComboBox to refect "Bob" as the selection and FirstName is the Bound column either from your RowSource query or table then just enter the following code: me![ComboBoxName] = "Bob". Now the combobox selection is Bob and the field in the Control Source will be updated with that information when the record is saved.

Just a thought. Couldn't figure out why you wanted to set the listindex property and thought this is what you were trying to do. Bob Scriver
 
YES, YES, that is exactly what I wanted to do.

THANKS
 
I don't know where you are getting this information but the listindex property seems to be read-only. Here is the ACCESS help on this property:
LISTINDEX property

You can use the ListIndex property to determine which item is selected in a list box or combo box.
Setting
The ListIndex property is an integer from 0 to the total number of items in a list box or combo box minus 1. Microsoft Access sets the ListIndex property value when an item is selected in a list box or list box portion of a combo box. The ListIndex property value of the first item in a list is 0, the value of the second item is 1, and so on.
This property is available only by using a macro or Visual Basic. You can read this property only in Form view and Datasheet view. This property is read-only and isn't available in other views.[

I tested this in both ACCESS 97 and 2000 and the same thing happens in both. I can read the property but cannot change it. ACCESS is in control of the property and wouldn't want you changing it as you may assign a value that is out of bounds.

Let me know if you find out something different or post the threads that show how to update the property.


Bob Scriver
 
Great. We passed each other on the last postings. Glad that things are working now. Bob Scriver
 
First, THANK YOU for your timely support in answering my question.

Second - Yes, thanks to your help, I got my app working exactly as I want.

Third - OK, NOW I see what the problem is. I quoted what was in the "Example" section at the bottom of the page. I see what you quoted at the top of the same page. Apparently, there is a disconnect between what a macro or Visual Basic can do, and what the form's code module can do. This seems to be CRAZY. ANY control SHOULD have the property exposed the SAME way whether it is in the form's module or in a macro. I'm understanding more and more why my coworker programs in Paradox. I'll have to read the help files more closely.


Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top