473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 9203
ADezii
8,834 Expert 8TB
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, 683 views)
Dec 16 '10 #2
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 Expert 8TB
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.