help with SQL statement

  • Thread starter Thread starter gls858
  • Start date Start date
G

gls858

I'm trying to add to a database that was designed by someone
else. Add to that my lack of understanding SQL and I obviously have
a problem :-) I've manage to get this far by mimicking existing sql statements.

sql = "SELECT ECNHDetail.* INTO 2005ECNHDetail" & _
"FROM ECNHDetail" & _
"WHERE (((ECNHDetail.InvoiceDate) >= #" & txtStartDt & "# And
(ECNHDetail.InvoiceDate) <= #" & txtEndDt & "#));"

DoCmd.RunSQL sql

ECNHDetail is a table containing sales history for 3 years. I want to
do a make table and create a table for just one year 2005ECNHDetail
based a date range. I have a form to select the dates and customer.
Right now I'd be happy just to get this part to run. I get

Runtime Error 3067
Query must contain at least one table or query

ECNHDetail is a table. What am I missing?
 
You need to add space in the end of each the line


sql = "SELECT ECNHDetail.* INTO 2005ECNHDetail " & _
"FROM ECNHDetail " & _
"WHERE (((ECNHDetail.InvoiceDate) >= #" & txtStartDt & "# And
(ECNHDetail.InvoiceDate) <= #" & txtEndDt & "#));"
 
Ofer said:
You need to add space in the end of each the line


sql = "SELECT ECNHDetail.* INTO 2005ECNHDetail " & _
"FROM ECNHDetail " & _
"WHERE (((ECNHDetail.InvoiceDate) >= #" & txtStartDt & "# And
(ECNHDetail.InvoiceDate) <= #" & txtEndDt & "#));"
I see now that the Where statement wrapped. It's really on one line.
I know this will sound clueless ( which is true) but exactly where
should the spaces be, after the name or the " or the &.

Thanks for the help

gls858
 
The problem Ofer was trying to highlight is that you didn't have a space,
for instance, between 2005ECNHDetail and FROM , nor between ECNHDetail and
WHERE due to how your string was constructed. You need to add spaces as
indicated in the response Ofer gave you.
 
Douglas said:
The problem Ofer was trying to highlight is that you didn't have a space,
for instance, between 2005ECNHDetail and FROM , nor between ECNHDetail and
WHERE due to how your string was constructed. You need to add spaces as
indicated in the response Ofer gave you.
Thanks Doug. I just did figure it out by trail and error right before I
read your reply :-) I find the syntax in SQL quite confusing.

gls858
 

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

Back
Top