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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ques. on list box Multi select setting in VBA

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
US
I am trying to set the multi select property of a list box on an Access 2000 form thru VBA code. 'Help' says this property can be set this way, but when I try to execute the code: lstCourses.multiselect = 2 I get an runtime error that says a value cannot be assigned to that property.

Can the multiselect property of a list box be set/changed thru VBA code? If so, any example of the correct syntax?

Thanks for any help on this.
 
The help file for MultiSelect indicates this property can ONLY be set while the form is in DesignView. So you would have to open the form in DesignView, set the property, save the form, then open it normally for your user.

Or you could put two listboxes on the form, one normal select and one multi and just show or hide the appropriate one a necessary?

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
OK, but 'Help' is confusing as it does say the following:

"You can set the MultiSelect property by using the list box's property sheet, a macro, or Visual Basic.
This property can be set only in form Design view."

Help even gives the values if one is to use VBA in a nice little chart: 0 for None, 1 for Simple and 2 for Extended. A person would only used these values in VBA.

If it can only be set in Design view, so be it, but then Help is giving confusing info on this.

Thanks for your quick response.
 
Well....in VBA code, you CAN open a form in design view and do things to it......

That is what you would have to do in this case.

DoCmd.OpenForm Name, acDesign will open it in design view, use the code in the help file to set it, DoCmd.Close acForm, Name, acSaveYes to close and save, then DoCmd.OpenForm Name to open normally.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Thanks.

Opening in design view isn't practical in my application, so we go with a plan B, or something.

Thanks again.
 
One more option that comes to mind is to set the listbox to mutli always. Then when validating other data, check if this should be one selection or if it allows many. If single, check to see how many are selected in the listbox and report back to the user if more than one are selected.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
How are ya batteam . . .

Normally this is a design view set an forget property.

Curious as to whats causing you to have to program the property?

Calvin.gif
See Ya! . . . . . .
 
Opening in design view isn't practical in my application
you may try this:
DoCmd.OpenForm FormName, acDesign, , , , acHidden

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top