insert into code snippet

  • Thread starter Thread starter seeker
  • Start date Start date
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) & ")"
 
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
 
Back
Top