koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
I am trying to insert data from a form into a table in Access. The scenario is:
I have a table that contains issues. I also have a table with assigned issues where records are entered when an issue is being assigned to an employee. There are times when multiple issues are assigned to one employee. The table with the assigned issues contains fields like Assigned Date, Assigned To, etc. that will be the same for every issue assigned. The actual issue will be different however.
From the Issues table, I need the IssueID, the OpenedDate and the Select field.
On the form, I have unbound controls where the DateAssigned, AssignedTo, AssignedBy, Priority and AssignedNotes are entered.
The form is unbound but I have a subform which is just being used to select the records to be assigned. I have additional fields on the subform so that you can see the issue name, type, etc. With the exception of the Select field, the subform controls are locked. The fields are only there so the user can actually see the details of the records to be assigned.
Now here is the issue:
I am using an SQL Insert Statement which works fine until I add the Where Clause. I have tried several ways to add the Where clause but to no avail. I need the where Clause because I only want to insert the records that have been checked (=true). Here is my code:
Without the Where clause, the code works but only the first record is inserted into the table but I need to insert all of the selected records.
I have been doing some online searching but I am still unable to figure out what is wrong with the where clause.
Thanks in advance for any assistance.
Cheers!
I have a table that contains issues. I also have a table with assigned issues where records are entered when an issue is being assigned to an employee. There are times when multiple issues are assigned to one employee. The table with the assigned issues contains fields like Assigned Date, Assigned To, etc. that will be the same for every issue assigned. The actual issue will be different however.
From the Issues table, I need the IssueID, the OpenedDate and the Select field.
On the form, I have unbound controls where the DateAssigned, AssignedTo, AssignedBy, Priority and AssignedNotes are entered.
The form is unbound but I have a subform which is just being used to select the records to be assigned. I have additional fields on the subform so that you can see the issue name, type, etc. With the exception of the Select field, the subform controls are locked. The fields are only there so the user can actually see the details of the records to be assigned.
Now here is the issue:
I am using an SQL Insert Statement which works fine until I add the Where Clause. I have tried several ways to add the Where clause but to no avail. I need the where Clause because I only want to insert the records that have been checked (=true). Here is my code:
Code:
Dim strField1, strField2, strField3, strField4 As Integer
Dim strField5, strField6, strField7 As String
Dim strField8, strField9 As Date
Dim strSQL As String
strField1 = Nz(DMax("[AssIssID]", " tblAssignedIssue"), 0) + 1
strField2 = Field from Form 2
strField3 = Field from Form 1
strField4 = Field from Form 1
strField5 = Field from Form 2
strField6 = Field from Form 2
strField7 = Field from Form 2
strField8 = Field from Form 2
strField9 = Field from Form 1
strSQL = "INSERT INTO tblAssignedIssue ([Field],[ Field],[ Field],[ Field],[ Field],[ Field],[ Field],[ Field],[ Field]) " & _
"VALUES ('" & strField1 & "','" & strField2 & "','" & strField3 & "','" & strField4 & "','" & strField5 & "','" & strField6 & "','" & strField7 & "','" & strField8 & "', '" & strField9 & "') &_"
"WHERE ((([tblIssue]![Select] ='" & Forms![frmAssignIssue]![fsubIssue].Form![Select] & "'));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Without the Where clause, the code works but only the first record is inserted into the table but I need to insert all of the selected records.
I have been doing some online searching but I am still unable to figure out what is wrong with the where clause.
Thanks in advance for any assistance.
Cheers!