473,466 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I get MultiSelect list box to populate individual rows in a table?

9 New Member
Hi, I want to enter data about when people attend a group session and which session they attended.

On a Form:
I have a Multi-Select list box of people's names.
I have a text box where I type in the date.
I have a drop-down box for the group session name.

In a Table:
I have a column for name, a column for date, and a column for group session name.

On the Form, I want to be able to highlight several names from the Multi-Select list box, select a single group session name from the drown-down, type in a date, and then enter those records. If I highlighted three names (John, Dick, and Harry), then in my table I should get 3 new rows, one per person. Each row should have the person's name, the date, and the session he or she attended.

How can I do this?

Currently, I can enter the data just fine if I do it individually. However, sometimes 8-10 people take the same session, so it would be a lot easier if I could do what I described above. I have downloaded some VBA code to get me started, but I get a lot of "Type Mismatch" errors and Object not Defined errors.

Any help would be greatly appreciated. Thanks!
Dec 16 '10 #1
3 9233
ADezii
8,834 Recognized Expert Expert
Just subscribing, will return later...

A few, basic, assumptions that I made for this Demo:
  1. Table Name is tblSession consisting of the following Fields:
    1. [Name] - {TEXT}
    2. [Date] - {DATE/TIME}
    3. [Session Name] - {TEXT}
  2. Controls on the Form are named as follows:
    1. lstNames - ListBox containing Names (MultiSelect = Yes)
    2. cboSession - Combo Box containing various Sessions
    3. txtDate - Text Box to store the Date Field
    4. The above Controls are Unbound
  3. The following Code will write the Name(s) of the individual(s) selected, as well as the Session and Date to tblSessions:
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As dao.Database
    2. Dim varItem As Variant
    3. Dim lst As ListBox
    4.  
    5. Set lst = Me![lstNames]
    6.  
    7. Dim rst As dao.Recordset
    8. If lst.ItemsSelected.Count = 0 Or IsNull(Me![cboSession]) Or IsNull(Me![txtDate]) Then
    9.   MsgBox "You need to Select a Session(s), Name, and Date in order to proceed", vbExclamation, _
    10.          "Missing Data Input"
    11.            Exit Sub
    12. End If
    13.  
    14. Set MyDB = CurrentDb
    15. Set rst = MyDB.OpenRecordset("tblSession", dbOpenDynaset, dbAppendOnly)
    16.  
    17. With rst
    18.   For Each varItem In lst.ItemsSelected
    19.     .AddNew
    20.        ![Name] = lst.ItemData(varItem)
    21.        ![Date] = Me![txtDate]
    22.        ![Session Name] = Me![cboSession]
    23.     .Update
    24.   Next varItem
    25. End With
    26.  
    27. rst.Close
    28. Set rst = Nothing
    29.  
    30. DoCmd.OpenTable "tblSession", acViewNormal, acReadOnly
    31. DoCmd.Maximize
  4. Download the Attachment to see first hand operation.
  5. Any questions, please feel free to ask.
Attached Files
File Type: zip Populate_Table.zip (15.2 KB, 684 views)
Dec 16 '10 #2
Andy Sauer
9 New Member
This is a huge help, and you have gotten me to the 3-yard line. Your code works great, thanks so much!. It enters the data in individual rows.

After I click my button, it opens up the table so I can see the data have been entered. However, what would be really great is if it would move me to the next record so that I can continue entering patient/session information.

I tried to borrow the code from the "go to next record" button, but I'm getting errors that it can't go to specified record. Can you please help me finish the code so that it accepts the new data entries, and then moves me to the next record so I can continue entering? Here is what I tried adding to your code (right after the update part, oh, and my button is called ADD_NEW_RECORD_FOR_PATIENT):

.Update
Next varItem
End With

rst.Close
Set rst = Nothing

DoCmd.GoToRecord , , acNewRec

Exit_ADD_NEW_RECORD_FOR_PATIENT_Click:
Exit Sub

Err_ADD_NEW_RECORD_FOR_PATIENT_Click:
MsgBox Err.Description
Resume Exit_ADD_NEW_RECORD_FOR_PATIENT_Click

End Sub
Dec 17 '10 #3
ADezii
8,834 Recognized Expert Expert
It is rarely a good idea to enter Data directly into a Table:
  1. Create a Form whose Record Source is your Table
  2. After Adding Records to the Table for multiple Names via Code, Open the Form in ADD Mode, then ADD your additional Record(s) in this manner.
  3. The Code below will illustrate this point:
    Expand|Select|Wrap|Line Numbers
    1. 'Code intentionally omitted.......................................
    2. With rst
    3.   For Each varItem In lst.ItemsSelected
    4.     .AddNew
    5.        ![Name] = lst.ItemData(varItem)
    6.        ![Date] = Me![txtDate]
    7.        ![Session Name] = Me![cboSession]
    8.     .Update
    9.   Next varItem
    10. End With
    11.  
    12. rst.Close
    13. Set rst = Nothing
    14.  
    15. DoCmd.OpenForm "<Form Name Here>", , , , acFormAdd, acWindowNormal
    16. 'Code intentionally omitted.......................................
Dec 17 '10 #4

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

Similar topics

4
by: Jon McLean | last post by:
I fear that my question may be elementary, but what I am trying just is not working. I have two tables: tblContacts (Essentially a mailing list. Each contact has an Autonumber ID.)...
1
by: Jillian Cee | last post by:
I have a multiselect list box (simple). I need to find out how to get Access to recognise my multiple selections firstly (I believe) then I want these selections to go into a query so that I can...
3
by: Shannan Casteel via AccessMonster.com | last post by:
I have three main tables. The first is the table that my main form will be based on. This is where the user will enter all the data. The table is called TechnicalProblemsTable. It looks like...
2
by: Steph | last post by:
I have created a multiselect list box control (lbx_comorb) that is populated from a datatable (dt_ptAdmission). The list box populates now problem at all. However the issue is when I load the...
3
by: John | last post by:
Hi I am using the following get the items from a multiselect list; Dim ctl As Control For Each ctl In Me.BatchInvoicesList.ItemsSelected Problem is that I am getting a 'Object not found...
1
by: kak36 | last post by:
Hello and Help, Please. Using Access 2003, I am using a Multiselect List Box (simple) in the data entry window. Thanks to this site, I have created a Current Event to show the selected answer in a...
1
by: syam | last post by:
Hai Friends.. I have a search page and contains multiple multiselect list boxes, each containing 6 options. I want to check whether the user has checked atleast one option in each of...
7
by: jthep | last post by:
Hi, I'm a newbie at this but how can I populate a table with data from other tables by using INSERT statements? Below is of what I have so far, I have to populate the PERSON_PROFILE table. I've...
2
by: ...vagrahb | last post by:
I am having accessing individual rows from a multidimensional array pass to a function as reference CODE: function Declaration int Part_Buffer(char (*buffer),int Low, int High)
5
by: r3bol | last post by:
Hi, sorry to post this, but I've had a really hard time finding how to do it. Q. How can I break up a value in a list to a list of individual items (preferably without importing any modules)?...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.