[AccessD] Multi Select.

Darryl Collins darryl at whittleconsulting.com.au
Sun Dec 4 20:19:54 CST 2011


Doh... proof reading is important... proof reading is important...

" there is NO left to right sequence required  "

Bah..

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Darryl Collins
Sent: Monday, 5 December 2011 12:53 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Multi Select.

Hi Charlotte,

Yeah, that was my original idea, have one listbox set to multi and the other set to single and swap the visibility, but in reality that wasn't going to work functionally for what is required here.  Mainly as the process is not a linear one, so the user can 'go back' (so to speak) can change how many records are selected in either list box - or select them in any order, there is left to right sequence required   Of course choosing one of each only is also a valid option.

No, I ended up using option II I found on Google, which is to emulate what I was looking to do via code.

This works by first counting how many records are selected in the active listbox and setting a public Boolean variable.  I then use code like this

I use an onclick event to work out how many records are selected (If the other list box has more than one record select this stage is skipped as we have already set the select status on both boxes).

For i = 0 To lstBox1.ListCount - 1
    If lstBox1.Selected(i) = True Then
        x = x + 1
        strMaterialTypeName(x) = lstBox1.Column(0, x)

    End If
Next i

If x > 1 Then
    gbOutputMatTypeMS = False
Else
    gbOutputMatTypeMS = True
End If

'----------------------------------------------------------------------------

Then when the user clicks on the the other listbox we already know the status of the original listbox


If gbInputMatTypeMS = False Then
    For i = 0 To lstBox1.ListCount - 1
        lstBox1.Selected(i) = False
    Next i
    lstBox1.Selected(lstBox1.ListIndex + 1) = True End If

'------------------------------------------------------------------------------------------

Which will force the other listbox to only select the item click on by the user if the multiselect variable for the dependant listbox is set to FALSE (gbInputMatTypeMS=False).
This actually works rather well and painlessly.  It allows the user to automagically select whatever they want in any order and the listboxes adjust state accordingly depending on how many records are chosen in each listbox.

Cheers
Darryl

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: Monday, 5 December 2011 12:07 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Multi Select.

Simplest way to handle it is with stacked controls using the particular settings you need.  Just  set their visibility depending on the selection in listbox 2.  No need to make design changes to the form, which is what you're doing when you change the property of the control itself.

Charlotte Foust

On Sun, Dec 4, 2011 at 4:58 PM, Darryl Collins < darryl at whittleconsulting.com.au> wrote:

> It is not the active control itself, which I agree needs to retain its 
> state - at least while active, but the other listboxes on the form.
>
> For example I have a form where listbox 1's default setting is 
> 'multi-select' and if the user chooses more than one option from 
> listbox 1, then list box 2 can only allow a single option from its 
> list (so multi-select should = none for listbox 2).  However if list 
> box 1 has only one option selected than listbox 2 should allow 
> multi-select to be available.  So the multi-select status of listbox 2 
> has a dependency on what the user selects (or doesn't select) in 
> listbox 1 and visa versa.  If a user chooses multiple values in 
> listbox 2 first, then only a single option should be allowed from 
> listbox 1 and the status change from multi to single.
>
> Yep, I have a real live scenario where this has to happen.  I have a 
> work around which basically fakes that behaviour and it works ok.  I 
> can understand why you should not be able to change the state of the 
> active listbox, but you cannot change any listboxes on the form, 
> unless you are in design mode.
>
> Oh well.... Just curious - seems a bit like a case of laziness to me, 
> but there are often other implications I am yet to grasp, maybe this 
> is one of them.
>
> Cheers
> Darryl.
>
>
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com [mailto:
> accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
> Sent: Monday, 5 December 2011 11:46 AM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Multi Select.
>
> It makes sense to me.  A control is either going to be multiselect or not.
> Why would you even want to change it on the fly?
>
> Charlotte Foust
>
> On Sun, Dec 4, 2011 at 4:15 PM, Darryl Collins < 
> darryl at whittleconsulting.com.au> wrote:
>
> > Hmmmm... Turns out you can only set this property when the form is 
> > in design mode, even via VBA.  Why on earth would they do that?
> >
> > I have a couple of workarounds in the bag, so not looking for a 
> > solution (unless you have a really cool one you can share), but it 
> > seems like an odd thing to enforce on developers, especially as the 
> > form is nearly always going to be open and in use when you want to 
> > change that property 'on the fly'...
> >
> > Anyone got any thoughts on this?  Just curious.
> >
> > Cheers
> > Darryl.
> >
> >
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
>
>
> >
> >
> > Website: http://www.databaseadvisors.com
>
>
> >
> >
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
>
>
> Website: http://www.databaseadvisors.com
>
>
>
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
>
>
> Website: http://www.databaseadvisors.com
>
>
>
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list