Link to home
Start Free TrialLog in
Avatar of filtrationproducts
filtrationproductsFlag for United States of America

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.

 CurrentDb.Execute " INSERT INTO TASKLIST " _
        & "(AssignDone,TimeInvest) VALUES " _
        & "(#NOW()#, 1);" _
        & WHERE ("[TASKID]=""" & TASKIDSTR & """)

Open in new window


Thanks in advance!
Dan
Avatar of Anthony Berenguel
Anthony Berenguel
Flag of United States of America image

try this...
 CurrentDb.Execute " INSERT INTO TASKLIST " _
        & "(AssignDone,TimeInvest) VALUES " _
        & "(#NOW()#, 1);" _
        & WHERE ("[TASKID]= "'" & TASKIDSTR & "'")
ASKER CERTIFIED SOLUTION
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
????? 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
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.
Avatar of filtrationproducts

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 & ""