473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

List Box multiple selections

489 256MB
I've been looking for an answer to what seems like a simple question and haven't found one that makes sense to me. Here's what I'm trying to do. I have a table that has the twelve months of the year. Jan Feb Mar etc. I use this table in lost of different places where the user select the month that will be used in extracts. Now however I want to the user to be able to select multiple months. On my form I created a List box select the Months table and set the Multi select to simple. The list box shows up with the months and allows the user to select multiple months. I have set the Lost focus event with the following code.
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control, varItm As Variant
  2. Set ctl = Me![LstMonths]
  3. For Each varItm In ctl.ItemsSelected
  4.     VMon = ctl.Selected(Months)
  5. Next varItm 
I loop through the list but the months are not what I selected it's list nothing is selected. If I select three months it code loops through three times but with the first three items in the months table.
There is a yes/no column in the months table that I would like to mark as true for those months that the user selects.
Thanks for any help
Dec 27 '10 #1

✓ answered by ADezii

Assuming the following:
  1. Table Name is tblData, with Fields:
    1. Month {TEXT} - [Jan...Dec]
    2. Yes/No {YES/NO}
  1. The following Code, placed in the LostFocus() Event of your List Box will do the trick. Simply substitute your Table Name, Name of Field containing Month Values (Jan...Dec), and the Name of the YES/NO Field.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub lstMonths_LostFocus()
    2. Dim ctl As ListBox
    3. Dim varItm As Variant
    4.  
    5. Set ctl = Me![lstMonths]
    6.  
    7. If ctl.ItemsSelected.Count < 1 Then Exit Sub
    8.  
    9. For Each varItm In ctl.ItemsSelected
    10.   CurrentDb.Execute "UPDATE tblData SET tblData.YesNo = True WHERE tblData.Month = '" & _
    11.                      ctl.ItemData(varItm) & "'", dbFailOnError
    12. Next varItm
    13. End Sub

2 1628
ADezii
8,834 Expert 8TB
Assuming the following:
  1. Table Name is tblData, with Fields:
    1. Month {TEXT} - [Jan...Dec]
    2. Yes/No {YES/NO}
  1. The following Code, placed in the LostFocus() Event of your List Box will do the trick. Simply substitute your Table Name, Name of Field containing Month Values (Jan...Dec), and the Name of the YES/NO Field.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub lstMonths_LostFocus()
    2. Dim ctl As ListBox
    3. Dim varItm As Variant
    4.  
    5. Set ctl = Me![lstMonths]
    6.  
    7. If ctl.ItemsSelected.Count < 1 Then Exit Sub
    8.  
    9. For Each varItm In ctl.ItemsSelected
    10.   CurrentDb.Execute "UPDATE tblData SET tblData.YesNo = True WHERE tblData.Month = '" & _
    11.                      ctl.ItemData(varItm) & "'", dbFailOnError
    12. Next varItm
    13. End Sub
Dec 28 '10 #2
CD Tom
489 256MB
Yes, the list box uses the tbldata but only shows the month in the box.
Dec 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bob Parnes | last post by:
I cannot find a reference on identifying multiple selections in QListView. Apparently one has to iterate through all the items and test each individually, but I don't know how to do the iteration....
1
by: theoryboy | last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist using a control-click. I've bound control-click to a function that uses selection_set to add to the selection, but it doesn't...
1
by: jeffgeorge | last post by:
Trying to create multiple acct reports based on the selection in a list box. I've set the list box for multiple selections, and in the report data source, I have a SQL statement which is reading...
2
by: Craig B. | last post by:
I am relativly new to access 2000 and am having some trouble with a report. I am not sure what I want to do is something I can do in access. I want to be able to choose from a combo box multiple...
0
by: gabe_pu | last post by:
List Box Multiple Selections I have a list box on my page and I´m trying to add new items on it. The insert operation must be under the selected item. When I make the insertion it is done ...
1
by: Yvonne | last post by:
We have a Contacts database which categorises our Contacts by three categories eg Country, Language and Skills. It has a combo box ( not bound) which is populated from a union query that gets its...
8
by: antheana | last post by:
Hi there, I am trying to create a tblMailingList, but am a little stuck on multiple selections. The people that have opted into this mailing list will be given a list of different interests they...
4
by: tbayse | last post by:
Hello, I have a question about making multiple selection queries in Access. I am running windows XP and Access 2003. Up until this point I had a form where a user would make single selections from...
0
by: Gunnar Hurtig | last post by:
Hi All I am relatively new to Tkinter and am putting a wraparound to the ATNF ASAP program. In one part I present several long lists in list boxes for selection. My code will remember the multiple...
0
by: Germaris | last post by:
Hi there! Is it possible to make multiple selections in a ComboBox ? i.e. make n consecutive selections and store them in an array or make n selections in the open list of the CB by using (for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.