Add Record from Event Procedure

  • Thread starter ladybug via AccessMonster.com
  • Start date
L

ladybug via AccessMonster.com

I am trying to modify an existing database. There is a form with a subform.
I have added a combo box at the bottom of the main form called
txt_add_employee. I want the user to be able to make a selection in the
combo box and then click a button called btn_add_employee. This On Click
Procedure is supposed to add that selection (employee)to the list in the
subform.

Here is what I have right now in the Event Procedure behind the On Click
Button:
DoCmd.SetWarnings False
DoCmd.RunSQL ("INSERT INTO tbl_Attendees (Employee_ID) SELECT " & Chr(34) &
Forms!frm_Meeting!txt_add_employee & Chr(34))
Forms!frm_Meeting!sfrm_Attendees!Employee_ID.Requery

Nothing happens when a selection is made in the combo box and the
btn_add_employee is clicked.

The record source behind the form is:
SELECT tbl_Meeting.Meeting_ID, tbl_Meeting.Meeting_Date, tbl_Meeting.
Meeting_Type_ID FROM tbl_Meeting;

The record source behind the subform is:
SELECT tbl_Attendees.Attending_Meeting_ID, tbl_Attendees.Meeting_ID,
tbl_Attendees.Employee_ID, tbl_Employee.Employee FROM tbl_Attendees INNER
JOIN tbl_Employee ON tbl_Attendees.Employee_ID=tbl_Employee.Employee_ID ORDER
BY tbl_Employee.Employee;

The row source of txt_add_employee is:
SELECT tbl_Employee.Employee_ID, tbl_Employee.Employee FROM tbl_Employee;

Can someone please help?
 
J

Jeanette Cunningham

Hi ladybug,
assuming that the main form and subform have their link master and link
child fields set to the related field between the 2 table, use this
approach.

Using a combo box to find records
http://www.allenbrowne.com/ser-03.html

Instead of adding an employee to the subform, set it up so that access
automatically adds the correct employee to each subform record.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top