Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2006

Tip: Looking for answers? Try searching our database.

Listbox--actions based on selected items

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ndalton - 20 Jun 2006 12:35 GMT
I have a listbox with maybe 5 things in it.  The user will select from 1 to 5
of those things, and then click a button.

When the button is clicked, I want to go through every item in the listbox,
create a corresponding record in TableA for every selected item, and create a
corresponding record in TableB for every non-selected item.

I was using a For Each loop to go through each row in
Me.listBox.ItemsSelected and then using a DAO recordset with AddNew to add
records for each selected item, but I don't know what kind of loop to use to
look at EVERY item in the list box and then check each one to see if it's
selected or not.

I'm sure it's probably a simple solution; I just can't get it.

Thanks.
Douglas J Steele - 20 Jun 2006 13:18 GMT
Dim intLoop As Integer

 For intLoop = 0 To Me.listBox.ListCount
   If Me.listBox.Selected(intLoop) Then
' it's selected
   Else
' it's not selected
   End If
 Next intLoop

If you've set ColumnHeads to True, start at 1, not 0. You can accomplish
this generically using:

 For intLoop = IIf(Me.listBox.ColumnHeads, 1, 0) To Me.List0.ListCount

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I have a listbox with maybe 5 things in it.  The user will select from 1 to 5
> of those things, and then click a button.
[quoted text clipped - 12 lines]
>
> Thanks.
Klatuu - 20 Jun 2006 13:51 GMT
Dim intCount as Integer
Dim intMax as Interger

   intMax = Me!MyListBox.ListCount - 1
   For intCount = 0 to intMax
       If Me!MyListBox.Selected(intCount) Then
           'Do the Selected stuff here
       Else
           'Do the Not Selected stuff here
      End If
   Next intCount

> I have a listbox with maybe 5 things in it.  The user will select from 1 to 5
> of those things, and then click a button.
[quoted text clipped - 12 lines]
>
> Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.