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!
3 9203
Just subscribing, will return later...
A few, basic, assumptions that I made for this Demo: - Table Name is tblSession consisting of the following Fields:
- [Name] - {TEXT}
- [Date] - {DATE/TIME}
- [Session Name] - {TEXT}
- Controls on the Form are named as follows:
- lstNames - ListBox containing Names (MultiSelect = Yes)
- cboSession - Combo Box containing various Sessions
- txtDate - Text Box to store the Date Field
- The above Controls are Unbound
- The following Code will write the Name(s) of the individual(s) selected, as well as the Session and Date to tblSessions:
- Dim MyDB As dao.Database
-
Dim varItem As Variant
-
Dim lst As ListBox
-
-
Set lst = Me![lstNames]
-
-
Dim rst As dao.Recordset
-
If lst.ItemsSelected.Count = 0 Or IsNull(Me![cboSession]) Or IsNull(Me![txtDate]) Then
-
MsgBox "You need to Select a Session(s), Name, and Date in order to proceed", vbExclamation, _
-
"Missing Data Input"
-
Exit Sub
-
End If
-
-
Set MyDB = CurrentDb
-
Set rst = MyDB.OpenRecordset("tblSession", dbOpenDynaset, dbAppendOnly)
-
-
With rst
-
For Each varItem In lst.ItemsSelected
-
.AddNew
-
![Name] = lst.ItemData(varItem)
-
![Date] = Me![txtDate]
-
![Session Name] = Me![cboSession]
-
.Update
-
Next varItem
-
End With
-
-
rst.Close
-
Set rst = Nothing
-
-
DoCmd.OpenTable "tblSession", acViewNormal, acReadOnly
-
DoCmd.Maximize
- Download the Attachment to see first hand operation.
- Any questions, please feel free to ask.
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
It is rarely a good idea to enter Data directly into a Table: - Create a Form whose Record Source is your Table
- 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.
- The Code below will illustrate this point:
- 'Code intentionally omitted.......................................
-
With rst
-
For Each varItem In lst.ItemsSelected
-
.AddNew
-
![Name] = lst.ItemData(varItem)
-
![Date] = Me![txtDate]
-
![Session Name] = Me![cboSession]
-
.Update
-
Next varItem
-
End With
-
-
rst.Close
-
Set rst = Nothing
-
-
DoCmd.OpenForm "<Form Name Here>", , , , acFormAdd, acWindowNormal
-
'Code intentionally omitted.......................................
Sign in to post your reply or Sign up for a free account.
Similar topics
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.)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)
|
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)?...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |