insert into code snippet

S

seeker

What is wrong with this insert into query?

DoCmd.RunSQL "insert into los_service (member_number, los_staff,
los_service_date, los_end_time, service" & _
", locnbr, entered_in_MAF, entry_date, tcm_loc,
los_beg_time, nbr_of_minutes) values(select" & _
" member_number, los_staff, los_service_date,
los_end_time, service, locnbr, entered_in_MAF," & _
" entry_date, tcm_loc from los_service where id = " &
id2 & ", #" & endtime1 & "#, " & _
DateDiff("n", endtime1, endtime2) & ")"
 
J

John Spencer MVP

You are trying to combine two different syntaxes.

INSERT INTO X (List of Fields)
SELECT (list of fields)
FROM Y
WHERE ...

OR (for one record and a list of values)

INSERT INTO X (List of Fields)
Values (list of values)

Given that and assuming that you have tow times endTime1 and EndTime2 that are
variables, you might want your query string to look like

DoCmd.RunSQL "insert into los_service (member_number, los_staff,
los_service_date, los_end_time, service" & _
", locnbr, entered_in_MAF, entry_date, tcm_loc" & _
", los_beg_time, nbr_of_minutes) " & _
"select member_number, los_staff" & _
", los_service_date, los_end_time, service" & _
", locnbr, entered_in_MAF, entry_date, tcm_loc " & _
", #" & endTime1 & "#, " & DateDiff("n", endtime1, endtime2) & _
" from los_service where id = " & id2

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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