Setting MultiSelect in code

G

Guest

Right now I have a form that has the multiselect property set to 0 as default
(set on form design), but in certain cases I wanted to be able to use
extended to make multiple selections (the extended depends for what that form
is currently being used for, the form is used multiple times in different
areas for somewhat similar operations but different data). I figured out how
to set the MultiSelect property in code to extended when the form opens.
I'm using the code below to accomplish that task. (form is the form that
will be using the extended multiselect property)

DoCmd.OpenForm "Form", acDesign
Forms![Form]!ListSearchResults.MultiSelect = 2
DoCmd.OpenForm "Form", , , , , acDialog

Everything works fine with this, but my problem is when I reuse the same
form (in another area that does not allow the selection of multiple rows), it
isn’t set back to 0 afterwards and reloading that form in design to set the
property back to 0 causes problems. I don’t want to set the property back to
0 in the areas that do not allow multiple selections since this form is used
in so many different areas while the multi-selections I need only exist in
one or two cases.

This is the code I use to try and set the property back to 0 (at the end of
the sub that opens the form).
DoCmd.OpenForm "Form", acDesign
Forms![Form]!ListSearchResults.MultiSelect = 0
DoCmd.Close acForm, "Form"

Thanks for any suggestions you might have to offer.
 
K

Ken Snell \(MVP\)

Put two listboxes on the form....one for single select, one for multiselect.
Make one or the other invisible depending upon which one you want to use.
 
G

Guest

You are not saving the changes to the form
DoCmd.OpenForm "Form", acDesign
Forms![Form]!ListSearchResults.MultiSelect = 0
DoCmd.Close acForm, "Form", acSaveYes

But then, is that necessary? If it can be different depending on how the
form is being used, why not just set it like you do in your first snippet
whenever you open it?
 

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