Add new records into source table on Form

F

Frank

I created a form for training records. The data source is table
TRAINING. The form has Combo box that is
used to select employee. When the employee is selected, the employee's
data, such as employee_id,
manager, phone, training_course display in the form. This part of the
form works well.

There was new request from my client. It's requsted that when the
training_course displayed on the form is changed, the record with new
training_course can be added into source table TRAINING. So, I created
"Add" buttorn on the form and used append query method to add the
records into the TRAINING table. However, it did
not work as I expected. Using append query method, all records of the
emplyee in the source table were added into the same (the table has
dupcate records), which is not I wanted. I just want to add the new
record of the employee (the record shown on the form) to be added into
the table. I am not expert on Access. I appreciate any of the help on
the issue.

Thanks

Frank
 
D

Daryl S

Frank -

You probably need some criteria in your append query to only append the
'current' record on the form. You can do this in query design by using the
build button when you are in the criteria row for the training course field.
You can test it if the form is open by switching to datasheet mode in the
query to see what would be added.
 
F

Frank

Frank -

You probably need some criteria in your append query to only append the
'current' record on the form.   You can do this in query design by using the
build button when you are in the criteria row for the training course field.  
You can test it if the form is open by switching to datasheet mode in the
query to see what would be added.
--
Daryl S






- Show quoted text -

Daryl,

I added criteria in my append query. I built 2 criteria: 1 [Forms]!
trainingForm]!employee_id] = training.employee_id. 2. Forms]!
trainingForm]!course_name] <>training.course_name.
After I applied these criteria in the query, no row was appended into
the table. However, If I took out criteria 2. all records with the
employee_id were append into the table.

Any idea?

Thanks

Frank
 
F

Frank

You probably need some criteria in your append query to only append the
'current' record on the form.   You can do this in query design by using the
build button when you are in the criteria row for the training course field.  
You can test it if the form is open by switching to datasheet mode in the
query to see what would be added.
- Show quoted text -

Daryl,

I added criteria in my append query. I built 2 criteria: 1 [Forms]!
trainingForm]!employee_id] = training.employee_id. 2. Forms]!
trainingForm]!course_name] <>training.course_name.
After I applied these criteria in the query, no row was appended  into
the table. However, If I took out criteria 2. all records with the
employee_id were append into the table.

Any idea?

Thanks

Frank- Hide quoted text -

- Show quoted text -

In addition, I used method of Insert record (see my code below). It
can update the reord, but can not add (insert) record. I don't know
why.


Frank


Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

CurrentDb.Execute "INSERT INTO training
(EMPLOYEE,Training_program_name, Training_date, Training_results,
manager, NUID,comments) Values('" & EMPLOYEE.Value & "', '" &
Training_program_name.Value & "', '" & Training_date.Value & "', '" &
Training_results.Value & "', '" & Manager.Value & "', '" & NUID.Value
& "', '" & Comments.Value & "' )"



Exit_Add_New_Record_Click:
Exit Sub
 
D

Daryl S

Frank -

What is the primary key on your TRAINING table? Any other Unique Keys?
These can prevent records from being added if the unique key already exists.

Also, for your query, you want the second criteria to be EQUAL TO the new
courst_name:

Forms![trainingForm]![course_name] = training.course_name

--
Daryl S


Frank said:
You probably need some criteria in your append query to only append the
'current' record on the form. You can do this in query design by using the
build button when you are in the criteria row for the training course field.
You can test it if the form is open by switching to datasheet mode in the
query to see what would be added.
:
I created a form for training records. The data source is table
TRAINING. The form has Combo box that is
used to select employee. When the employee is selected, the employee's
data, such as employee_id,
manager, phone, training_course display in the form. This part of the
form works well.
There was new request from my client. It's requsted that when the
training_course displayed on the form is changed, the record with new
training_course can be added into source table TRAINING. So, I created
"Add" buttorn on the form and used append query method to add the
records into the TRAINING table. However, it did
not work as I expected. Using append query method, all records of the
emplyee in the source table were added into the same (the table has
dupcate records), which is not I wanted. I just want to add the new
record of the employee (the record shown on the form) to be added into
the table. I am not expert on Access. I appreciate any of the help on
the issue.

Frank
.- Hide quoted text -
- Show quoted text -

Daryl,

I added criteria in my append query. I built 2 criteria: 1 [Forms]!
trainingForm]!employee_id] = training.employee_id. 2. Forms]!
trainingForm]!course_name] <>training.course_name.
After I applied these criteria in the query, no row was appended into
the table. However, If I took out criteria 2. all records with the
employee_id were append into the table.

Any idea?

Thanks

Frank- Hide quoted text -

- Show quoted text -

In addition, I used method of Insert record (see my code below). It
can update the reord, but can not add (insert) record. I don't know
why.


Frank


Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click


DoCmd.GoToRecord , , acNewRec

CurrentDb.Execute "INSERT INTO training
(EMPLOYEE,Training_program_name, Training_date, Training_results,
manager, NUID,comments) Values('" & EMPLOYEE.Value & "', '" &
Training_program_name.Value & "', '" & Training_date.Value & "', '" &
Training_results.Value & "', '" & Manager.Value & "', '" & NUID.Value
& "', '" & Comments.Value & "' )"



Exit_Add_New_Record_Click:
Exit Sub
.
 
F

Frank

Frank -

What is the primary key on your TRAINING table?  Any other Unique Keys? 
These can prevent records from being added if the unique key already exists.

Also, for your query, you want the second criteria to be EQUAL TO the new
courst_name:

   Forms![trainingForm]![course_name] = training.course_name

--
Daryl S



Frank said:
Frank -
You probably need some criteria in your append query to only appendthe
'current' record on the form.   You can do this in query design by using the
build button when you are in the criteria row for the training course field.  
You can test it if the form is open by switching to datasheet mode in the
query to see what would be added.
--
Daryl S
:
I created a form for training records. The data source is table
TRAINING. The form has Combo box that is
used to select employee. When the employee is selected, the employee's
data, such as employee_id,
manager, phone, training_course display in the form.  This partof the
form works well.
There was new request from my client. It's requsted that when the
training_course displayed on the form is changed,  the record with new
training_course can be added into source table TRAINING. So, I created
"Add" buttorn on the form and used append query method to add the
records into the TRAINING table. However, it did
not work as I expected. Using append query method, all records ofthe
emplyee in the source table were added into the same (the table has
dupcate records), which is not I wanted. I just want to add the new
record of the employee (the record shown on the form) to be addedinto
the table. I am not expert on Access. I appreciate any of the help on
the issue.
Thanks
Frank
.- Hide quoted text -
- Show quoted text -
Daryl,
I added criteria in my append query. I built 2 criteria: 1 [Forms]!
trainingForm]!employee_id] = training.employee_id. 2. Forms]!
trainingForm]!course_name] <>training.course_name.
After I applied these criteria in the query, no row was appended  into
the table. However, If I took out criteria 2. all records with the
employee_id were append into the table.
Any idea?
Thanks
Frank- Hide quoted text -
- Show quoted text -
In addition, I used method of Insert record (see my code below). It
can update the reord, but can not add (insert) record. I don't know
why.

Private Sub Add_New_Record_Click()
On Error GoTo Err_Add_New_Record_Click
    DoCmd.GoToRecord , , acNewRec
CurrentDb.Execute "INSERT INTO training
(EMPLOYEE,Training_program_name, Training_date, Training_results,
manager, NUID,comments) Values('" & EMPLOYEE.Value & "', '" &
Training_program_name.Value & "', '" & Training_date.Value & "', '" &
Training_results.Value & "', '" & Manager.Value & "', '" & NUID.Value
& "', '" & Comments.Value & "' )"
Exit_Add_New_Record_Click:
    Exit Sub
.- Hide quoted text -

- Show quoted text -

Daryl,

TAINING table does not have primary key and other unique keys. It can
have multipe records for employee_id. I do know why the second
criterial should be EQUAL TO instead of <>.

Thanks

Frank
 
D

Daryl S

Frank -

You want to add the new Training record that is on the form - the one with
the new training course - you don't want to insert records for all the other
training courses (they already are in the table).
 
F

Frank

Frank -

You want to add the new Training record that is on the form - the one with
the new training course - you don't want to insert records for all the other
training courses (they already are in the table).

--
Daryl S






- Show quoted text -

Yes, It's correct. When I used "<>" in criterial, not record can add
to the table becouase there is no such record in the table . When I
used "=", all data for the employee were added into the table. It
seems the append query won't work at all. is there any other way to
add (insert) record on the form into the source table.


Thanks
Frank
 
D

Daryl S

Frank -

Yes. The normal way to add new records is to use the form. You can use the
navigation buttons at the bottom (go the * record) and start entering data.
It will be saved automatically. If you don't need to see the existing
records, you can set the form property Data Entry to Yes, and it will come up
with a blank new record to be filled out (same form, different uses).
 

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