filtrationproducts
asked on
INSERT INTO command using WHERE option
Trying to use the INSERT INTO command to fill in a field in another table using the WHERE command.
Code attached - I am not sure this is the proper way to use WHERE with the INSERT INTO command. the TASKIDSTR string identifies which record to insert into.
Thanks in advance!
Dan
Code attached - I am not sure this is the proper way to use WHERE with the INSERT INTO command. the TASKIDSTR string identifies which record to insert into.
CurrentDb.Execute " INSERT INTO TASKLIST " _
& "(AssignDone,TimeInvest) VALUES " _
& "(#NOW()#, 1);" _
& WHERE ("[TASKID]=""" & TASKIDSTR & """)
Thanks in advance!
Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
????? the TASKIDSTR string identifies which record to insert into.?????
If that is the case you should be using an Update Query not a Append query. Just join the two tables based on the TASKIDSTR if this is the Key field and Update table2 fields with table1 fields, etc.
ET
If that is the case you should be using an Update Query not a Append query. Just join the two tables based on the TASKIDSTR if this is the Key field and Update table2 fields with table1 fields, etc.
ET
INSERT INTOI creates a new record, so a where statement on a values list is meaningless.I agree.
Please clarify what you are trying to accomplish.
ASKER
I updated my code to use the update command instead of insert into and it worked. Had to modify the code a little bit also.
CurrentDb.Execute "UPDATE PPAP " _
& "SET [AssignDone]='" & Now() & "',[TimeInvest]=1 " _
& "WHERE[TASKID] =" & TASKIDSTR & ""
CurrentDb.Execute "UPDATE PPAP " _
& "SET [AssignDone]='" & Now() & "',[TimeInvest]=1 " _
& "WHERE[TASKID] =" & TASKIDSTR & ""
CurrentDb.Execute " INSERT INTO TASKLIST " _
& "(AssignDone,TimeInvest) VALUES " _
& "(#NOW()#, 1);" _
& WHERE ("[TASKID]= "'" & TASKIDSTR & "'")