By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

ListBox Multiple selections

100+
P: 112
Hi, I am a newbie using Access 2003 and I am trying to select multiple values from a list box and put them in a text box on the same Form. The closest thing in the form pages that I can find is some code from an old post that select multiple values from a list box and put them in a text box on the another Form. I assume that this code runs off a button and I am not sure why it would run of the listbox.
If you are using VB 6 or below the problem is there isnt a .SelectedItems
Method, that is .NET and the link is for .NET, something like this could be of help to you

Going on the basis that your other form is called "MyFormName" which you can change lol, The text box you are transfering the information to is called "Text1" and the List


Code: ( text )
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim i As Integer
  3.  
  4.     MyFormName.Text1.Text = "" 'Clear The Text Box For Use
  5.     MyFormName.Text1.MultiLine = True 'Make Sure The Text Box Is Multiline
  6.  
  7.     'Loop through the items in the List Box (Named: List1)
  8.     For i = 0 To List1.ListCount - 1
  9.  
  10.         If List1.Selected(i) = True Then     'If The List Item Is Selected
  11.  
  12.             With MyFormName 'With The Other Form
  13.  
  14.                 .Text1.Text = .Text1.Text & List1.List(i) 'Add The Selected Text
  15.                 .Text1.Text = .Text1.Text & vbCrLf        'Next Line After The Added Text
  16.  
  17.             End With            'End With The Other Form
  18.         End If
  19.     Next
  20.     MyFormName.Show          'Show the other form.
  21. End Sub

Comments are included so that you can determine what each line of code does, (Turns green when in the code explorer screen), but i hope this helps you

Brief Rundown:
For i = 0 to List1.listcount - 1 : The listbox's list starts at 0, where as the count does not, so to stop it getting confused - 1 from the list count
vbCrLf: Next line
With MyFormName: means you dont have to type out MyFormName.Text1.Text everytime you want to do something with an object on that particular form.

Hope This Helps
Kind Regards
Devon.
Can anyone help me figure out how to do this? I have try to use this code and a few other I found but it just does not seem to work.
Oct 10 '07 #1
Share this Question
Share on Google+
1 Reply


nico5038
Expert 2.5K+
P: 3,072
Can you explain why you want to store multiple values in one field ?
It's against normalization and causes a lot of code to be written when you want to maintain this entered data in an update form....

Access 2007 however has a feature for muliple value fields, but there Access will show a list of all values with a checkbox to chose from...

Nic;o)
Oct 11 '07 #2

Post your reply

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