473,385 Members | 1,449 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,385 software developers and data experts.

Append Query - Only Appends 1 ID (Need more)!!

Hey,

I have 2 append queries. The first is based off of code given and works great. For the second, I followed the format of the 1st and adjusted it to meet my needs. Query 1 works great. It appends each specific clientId to the table when the command button from form 1 is selected (code below). The 2nd query works as well. But it will only append 1 employee record to the table. I thought this must be because it is only allowing for 1 clientID to be appended, but when I switch to a different client and try to append an employee, it has the same response (not allowing it). If anyone has suggestions I would appreciate them. Thanks.

Background: 2 tables are being appended to. Table1 (tblAnswers), query1 (qryappendSelect), and form 1 all work perfectly. Table 2 (tblAnswersEmployee) follows the same format as tblAnswers, except it includes a EmlpoyeeId field. Qry2 and Form 2 were based off of the respective 1, qry2 had some code alterations to append the correct fields.


Query 1
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblAnswers ( ClientAutoID, QuestionNumber )
  2. SELECT tblClient.ClientAutoID, tblQuestions.QuestionNumber
  3. FROM tblClient, tblQuestions
  4. WHERE (((tblClient.ClientAutoID)=[Forms]![frmClient]![ClientAutoID]) AND ((tblQuestions.QuestionNumber) Not Between 601 And 799));
Form 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub Update_Click()
  2. On Error GoTo Err_Update_Click
  3.     Dim stDocName As String
  4.     stDocName = "qryAppendSelect"
  5. If Nz(DLookup("[ClientAutoID]", "tblAnswers", "[ClientAutoID]=" & Me.ClientAutoID), 0) = 0 Then
  6.    DoCmd.OpenQuery stDocName, acNormal, acEdit
  7. End If
  8. Exit_Update_Click:
  9.     Exit Sub
  10. Err_Update_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Update_Click
  13. End Sub
Query 2
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblAnswersEmployee ( ClientAutoID, EmployeeAutoID, QuestionNumber )
  2. SELECT tblEmployee.ClientAutoID, tblEmployee.EmployeeAutoID, tblQuestions.QuestionNumber
  3. FROM tblQuestions, tblEmployee
  4. WHERE (((tblEmployee.EmployeeAutoID)=[Forms]![sbfEmployee1]![EmployeeAutoID]) AND ((tblQuestions.QuestionNumber) Between 601 And 605 Or (tblQuestions.QuestionNumber) Between 701 And 704)); 
Form 2
Expand|Select|Wrap|Line Numbers
  1. Private Sub Update_Click()
  2. On Error GoTo Err_Update_Click
  3.     Dim stDocName As String
  4.     stDocName = " qryEmployeeAppendSelect"
  5. If Nz(DLookup("[EmployeeAutoID]", "tblAnswersEmployee", "[ EmployeeAutoID]=" & Me.EmployeeAutoID), 0) = 0 Then
  6.    DoCmd.OpenQuery stDocName, acNormal, acEdit
  7. End If
  8. Exit_Update_Click:
  9.     Exit Sub
  10. Err_Update_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Update_Click
  13. End Sub
Dec 18 '06 #1
5 2047
MMcCarthy
14,534 Expert Mod 8TB
Robert in Query 1 we were allowing for the fact that each client needed to correspond to all questions. The second query is different because each client won't correspond to all Employees.

As you have put ClientAutoID in tblEmployees that means each employee only has one client. This doesn't sound right - can you confirm?

Mary
Dec 19 '06 #2
Robert in Query 1 we were allowing for the fact that each client needed to correspond to all questions. The second query is different because each client won't correspond to all Employees.

As you have put ClientAutoID in tblEmployees that means each employee only has one client. This doesn't sound right - can you confirm?

Mary
Sorry for the confusion. The Employees discussed are the ones who work for the client. So each client (company) can have several employees. Each employee should only have 1 client (company).

I will try to look at my DB from an outside perspective when posting. I just take it for granted ya’ll all know what I’m thinking when I type which of course is not the case. So my bad. Thanks again.
Dec 19 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Sorry for the delay in replying Robert. Can you post the structure of the tblEmployees and tblEmployeeAnswers tables for me to look at.

Mary
Dec 20 '06 #4
Sorry for the delay in replying Robert. Can you post the structure of the tblEmployees and tblEmployeeAnswers tables for me to look at.

Mary
Sure thing.

tblEmployee:

EmployeeAutoID (PK); ClientAutoID (FK) linked to tblClient 1 to many; the other fields are all general employee information (name….).

tblAnswersEmployee:

EmployeeAnswerAutoID (PK); EmployeeAutoID (FK) linked to tblEmployee 1 to many; ClientAutoID (FK) linked to tblClient 1 to many; QuestionNumber (FK) linked to tblQuestions 1 to many; EmployeeAnswer.
Dec 21 '06 #5
MMcCarthy
14,534 Expert Mod 8TB
Robert,

Try this. I've moved some of the Brackets. Copy and paste it as is. Access may add some more don't worry about it. If this doesn't solve the problem email me the database after christmas and I'll have a look.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblAnswersEmployee (ClientAutoID, EmployeeAutoID, QuestionNumber )
  2. SELECT tblEmployee.ClientAutoID, tblEmployee.EmployeeAutoID, tblQuestions.QuestionNumber
  3. FROM tblQuestions, tblEmployee
  4. WHERE ((tblEmployee.EmployeeAutoID = [Forms]![sbfEmployee1]![EmployeeAutoID]) 
  5. AND ((tblQuestions.QuestionNumber Between 601 And 605) 
  6. Or (tblQuestions.QuestionNumber Between 701 And 704))); 
  7.  
Merry Christmas

Mary
Dec 21 '06 #6

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

Similar topics

2
by: JMCN | last post by:
hi i have a general question regarding append queries in access 97. each week i need to update my table(tblonlinereg) with new or modified records. firstly, i import the text file into my...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
1
by: aaronm49 | last post by:
I have created an append query and I am having a problem with the format of the number column when it appends. For example. 4.5 appends as 4,a value of .5 appends as 0. I have adjusted the append...
1
by: David Barger | last post by:
Greetings, It appears that an Append Query I run in Access XP is randomly failing to append a field. I have payroll data being entered into a payroll database. This data is exported daily to...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
1
by: Geoff | last post by:
I am running an append query using query by example (but included equivalent SQL code). The query counts the number of bookings and appends this number to bookings to Tbl_Weekly INSERT INTO...
1
by: James Hallam | last post by:
I have a form with a subform. When there are no entries in the subform, I have an append query which makes a default entry in the subform (for what I am doing there needs to be at least one value...
3
by: DHarris | last post by:
I created a continuous form in Access2003 based on a query that users review customers and once reviewed clicks on a command button that executes an append query to update a table of the reviewed...
8
jinalpatel
by: jinalpatel | last post by:
I have two tables. tblClass and tblWithdrawn. On my main form(bound to tblClass) I have several data entry fields like Date withdrawn, Status (active or withdrawn) Date Classified etc. Also...
16
by: iheartvba | last post by:
Hi, I have a simple append query which takes data from a form and appends it into a table. INSERT INTO tblSmsSent ( MobileNumber, ClientName, TimeSent, AppointmentTime, AppointmentDate )...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.