Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MultiSelect Listbox 1

Status
Not open for further replies.

achiola

MIS
Apr 26, 2001
44
US
Ok guys,
A lot of us novice users are trying to figure this out. I have read through past posts and have seen many people asking this question. It concerns creating multiselecting listboxes and getting that data to a table. For those of you proficient in Access, and Visual Basic code I would imagine you have done something like this. Well, a lot of us could use a simple step by step example of how to do this. If your going to answer this post please assume that beginning users of access are reading it.

Here is the FORM:

Date __6/15/01____

Favorite Color(s)______ (let's say I chose blue & green)

Name__Nino_____



Now, let's say on my form I input the date, two color choices, and my name. I want the table to look like this:

6/15/01 blue Nino
6/15/01 green Nino

Does anybody know how to do this? I can't imagine that this solution should be so hard to find or implement.

Nino

 
Create a new table.
Create a form.
Define the form's field properties.
Save the form and fill it out.
Thusly,
Code:
Table Name: ArtistsFavoriteColors

        Name           Type           Size

Fields: ArtistID       Long Integer   4
        ArtistName     Text           25
        FavoriteColor  Text           15

Form:
  Text Box:  txtArtistID    Autonumber or type it in
  Text Box:  txtArtistName  Type it in
  Combo Box: cboFavColor    Type your list

Combo box properties:
  Control Source:    FavColor
  Row Source Type:   Value List
  Row Source:        Type this in: 
                      Red;Blue;Yellow;Fuscia;
                      Vermillion;Mustard;Olive;
                      Electric Blue

Save the form as EnterColors, then open and fill it out.

Hope this helps. If you need more info just ask.
:)


Gus Brunston
An old PICKer
padregus@home.com
 
Well, I forgot the date.
Put another field in the table: DecisionDate.
Put a text box in the form, call it txtDecisionDate.
In the property sheet for txtDecisionDate, enter Default Value: Date()
Format it for whatever date format you prefer.
When you fill out the form, you can elect the default date, or enter your own.
Cheers Gus Brunston
An old PICKer
padregus@home.com
 
In the form's property sheet (you get there by clicking the square to the left of the ruler in design view),

Code:
Date Record Source: ArtistsFavoriteColors

The table should be named "tblArtistsFavoriteColors", for the sake of normalization(?)

I probably forgot a bunch of other stuff, too... Gus Brunston
An old PICKer
padregus@home.com
 
Of course, it's not "Date Record Source" but just "Record Source"...Why am I doing this? Gus Brunston
An old PICKer
padregus@home.com
 
Did I say "click"? You must right click on that square to access the property sheet for the form.

I've just created the entire database for this. (I know, get a life.) If you want it send your email address to padregus@home.com and ask for "dbm ArtistsColors"

B-( Gus Brunston
An old PICKer
padregus@home.com
 
looks as if Gus forgot the multiselect part!
my suggestion! Using DAO.
create a table with 3 fields name it mytable
FavoriteColor = text
Datefield = date/time
respondentName = text

create a form with
two unbound text fields named frmDatefield ,frmrespname and a listbox named list0
set source to value list and use gus's color examples above
set multiselect to either simple or extended you choose

now based on some event I will suggest a submit button
create a button on the form and in its on click event place this code

Dim db As Database
Dim rs As Recordset
Dim varItem As Variant

Set db = CurrentDb
Set rs = db.OpenRecordset("mytable") 'opens record set

With rs
For Each varItem In List0.ItemsSelected 'cycle thru selected items
.AddNew 'readys recordset for adding
!FavoriteColor = List0.ItemData(varItem) adds color to table
!Datefield = me!frmdatefield 'adds date
!respondentName = me!frmrespname 'adds name
rs.Update 'updates table
Next varItem 'moves to next item in list0
End With

rs.close: Set rs = Nothing 'close record set
simple as that!
 
Didn't forget it...never saw that there thing before!
(-:
Gus Brunston
An old PICKer
padregus@home.com
 
The problem is that I need the multiselect listbox to be defined by the user's input. I don't want selections to be available, I want the user to be able to type in thier choices. Does anybody know how to do that?

Nino
 
Boy, you really ask some questions. Here it goes: Follow all of the stuff you saw in the response by BrainDead2. That is how you save the info into the table. To populate the combo box by user input, I would put two new controls on the form: a textbox called txtInput and a commandbutton call cmdEnter. place the textbox over the combo box. Set the combo box to RowSourceType = "Value List". After the user puts an entry into the txtInput they press the cmdEnter button and on the buttons ONClick event put this:

Private Sub cmdEnter_Click()
Dim strInput as string

if isnull(me.txtInput) or me.txtInput = "" then exit Sub

strInput = me.cboColors.Rowsource

strinput = strinput & Me.txtinput & ";"

me.cboColors.rowsource = strinput

End sub

That should work for letting the users determine their inputs then use the DAO routine above to add then to the table.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top