NewBaby:Multiple Selection in ListBox!

asdaqamin

Asdaq Amin
Local time
Today, 23:38
Joined
Nov 29, 2005
Messages
33
I am designing a small database.
I have problem in selecting Mutiple list values from list box.

I have a table of Personal.With fields
SrNo ------------- autonumber
Name -------------- Text
Age ---------- Number
Interset ------------ (Text)
//In Interset Properties through lookup tag I have
Display Control -------ListBox
Row Source Type --------- Value List
Row Source ---------------- "Swimming","Football","Cricket",hockey"

When I made form I got all the List Box Items. For single Selection it has worked. But If I want Multiple selection. I changed the property List Box property Multi Select from "None" to Simple. Now It worked with Multiple Selection.But If one first record I select Swimming, Football.On second record it would be blank. And select my self. But the previous one is saved on all the next records.If two selction on first next all same selction with 2.
If three then three.

I want Individual selection. It must be saved.According to corresponding record.

Facillitate in this regard is much appreciated.
 
Last edited:
Now If I normalize the Interest/Hobbies in Seperate Table.
Such as
SrInterest (autonumber)
Interest (Text)

The make Relationship.

Make SrInterest as Foregin key in the Personal table. In the form I can get the all values in the Listbox but how can I store it in Sigle field.
Selection of Multiple fields.???

Please if there the game is solved with VBA code please give me help I can do it.
Although I dont know the VBA.
Please mentioned the Steps.
 
Can any one solve my problem please.
I am very greatfull to you.

Plz guide me.
For Multi selction of ListBox items.
 
Below is a piece of code I use in one of my databases

Private Sub cmdPrintSelectedRecords_Click()

Dim varGetRecordSelectionC0 As Variant
Dim varGetRecordSelectionC1 As Variant
Dim fSelectionsFound As Boolean
Dim intSelectionListCounter As Integer

On Error Resume Next

txtDummy.SetFocus
cmdPrintSelectedRecords.Enabled = False

DoCmd.RunSQL ("DELETE tbl4202_Printer_COMMs_Data_for_Printing.* FROM tbl4202_Printer_COMMs_Data_for_Printing;")

For intSelectionListCounter = 0 To lstDisplayPrinterInfo.ListCount

If lstDisplayPrinterInfo.Selected(intSelectionListCounter) = True Then

fSelectionsFound = True

varGetRecordSelectionC0 = lstDisplayPrinterInfo.Column(0, intSelectionListCounter)
varGetRecordSelectionC1 = lstDisplayPrinterInfo.Column(1, intSelectionListCounter)

DoCmd.RunSQL ("INSERT INTO tbl4202_Printer_COMMs_Data_for_Printing ( txt4202_Printer_COMMs_Data, dtmDate_Time_Printer ) " & _
"SELECT '" & varGetRecordSelectionC0 & "', '" & varGetRecordSelectionC1 & "';")

End If

Next intSelectionListCounter

If fSelectionsFound = True Then

DoCmd.OpenReport "rpt4202_Printer_COMMs_Data_for_Printing", acViewNormal

lstDisplayPrinterInfo.Requery

End If

cmdPrintSelectedRecords.Enabled = True

End Sub
 
Or you could use the following example.

Firstly take out the Record Source in the listbox properties.

Open up vba, and copy the code changing the following bits of information:-

  • Where you see List22 replace it with the name of your listbox.

  • Replace Field Name and Table Name on the sSQL line to relate to your table and field.
e.g. sSQL = SELECT DISTINCT Field Name FROM Table Name ORDER BY Field Name


  • Replace the Field Name in the square brackets on the following line to match your field name, and don't forget to change the name of the listbox.
Me.List22.AddItem rst![Field Name]

Code:
Private Sub Form_Load()

Dim db As Database
Dim rst As DAO.Recordset
Dim sSQL As String
Me.List22.RowSource = ""

Set db = CurrentDb()
sSQL = "SELECT DISTINCT Interest FROM Hobbies ORDER BY Interest"

Set rst = db.OpenRecordset(sSQL, dbOpenDynaset, dbSeeChanges)

Do While Not rst.EOF
    Me.List22.AddItem rst![Interest]
    rst.MoveNext
Loop

rst.Close
Set rst = Nothing

End Sub

Hope that makes sense
 

Users who are viewing this thread

Back
Top Bottom