Multi Select List Box (1 Viewer)

syoung7903

Registered User.
Local time
Today, 23:04
Joined
Jan 1, 2001
Messages
18
I am a novice at multi select list boxes and could use some help. I have a very simple situation that I am trying to learn from. I have the following tables:

Rooms (one field - RoomName)
Areas (one field - AreaName)
Test (two fields Room and Area)

I have created a form I will call Form1. On it I have two list boxes. List Box one is called areas and it's row source is the Areas table. List Box two is called rooms and it's row source is the Rooms table. The Rooms list box is a simple multi select. The Areas list box is not a multi select box.

I have placed a button on the form with the following code for the On Click Event:

Dim Room As Variant
Dim Area As Variant
For Each Room In Rooms.ItemsSelected
For Each Area In Areas.ItemsSelected
DoCmd.RunSQL "INSERT INTO Test(Room,Area) VALUES (Room.itemdata(room),Area.itemdata(area))"
Next
Next

My hope is that I can select several rooms (for example 3) and one area and that when I click on the command button I will find three records in the Test Table. Room1 and Area, Room2 and Area, and Room3 and Area.

I notice (since I did not set warnings to false) that it is attemping to insert three records but when I look at the table there are three blank records.

Like I stated earlier. I am not a seasoned user of ItemSelect and Itemdata. Any help would be greatly appreciated.
 

Users who are viewing this thread

Top Bottom