David Emerson
davide at dalyn.co.nz
Thu Sep 25 15:57:38 CDT 2003
Thanks. I much appreciate the help from all on this one. David At 25/09/2003, you wrote: >Hi David > >Well, how about the Click event ...? >This will also fire when using keys. > ><code> > > Dim lst As ListBox > > Dim lngIndex As Long > Dim strKey As String > Dim booSelected As Boolean > > Set lst = Me!lstDemo > With lst > lngIndex = .ListIndex + Abs(.ColumnHeads) > strKey = .ItemData(lngIndex) > booSelected = .Selected(lngIndex) > End With > > MsgBox strKey & ":" & Str(booSelected) > > If booSelected = True Then > ' Append strKey to collection/selection. > Else > ' Remove strKey from collection/selection. > End If > > Set lst = Nothing > ></code> > >However, the event will fire also when using the navigation keys. >Thus, I would follow the advice of Drew to append/remove the selected >items to an (interim) collection or array and only run the >append/delete action query (or code) on the table if an item really is >appended or removed from the collection or array. > >/gustav > > > > How do I determine which item has just been selected/deselected? Then I > > could add it if selected, or delete if deselected. > > > >>It sounds/looks like you are building the complete list every time an > >>item is selected. Why not add only that item which has been selected? > >> > >>/gustav > >> > >> > >> > I have a listbox which is used to select clients for including in > >> > reports. When the listbox is updated I have a separate text box that > >> > shows > >> > the names of the clients selected and the number selected. At the same > >> > time I store the ID's of the clients in a table that is used to > filter out > >> > the required client records. The initial list box has over 1800 > names. It > >> > is taking about 10 seconds to update the lists each time a client is > >> > selected. If I rem out the adding of ID's to the table then the time > >> > reduces to about 3 seconds. The main part of the code is - > >> > >> > With Me!lstClientList > >> > For Each varItem In .ItemsSelected > >> > If .Selected(varItem) = True Then > >> > strList = strList & .Column(1, varItem) & vbCrLf ' > Adds > >> > client name to selected list > >> > intClientNo = intClientNo + > >> 1 ' > >> > Counts number of selected clients > >> > rst.AddNew > >> > 'Add client ID to table > >> > rst!CustIDNo = .Column(0, varItem) > >> > rst.Update > >> > End If > >> > Next varItem > >> > End With > >> > >> > Any thoughts as to how I can speed up the process? The BE is SQL2000. > >_______________________________________________ >AccessD mailing list >AccessD at databaseadvisors.com >http://databaseadvisors.com/mailman/listinfo/accessd >Website: http://www.databaseadvisors.com