Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into Help

Status
Not open for further replies.

bubba100

Technical User
Nov 16, 2001
493
US
I am tying to add a second critera to the following insert query but can't get the syntax correct.
This works:
DBS.Execute "INSERT INTO SLIC_Trips " _
& "Select * " _
& "From [SLIC_Trips_All] " _
& "Where SLIC_Trips_All.District='" & [Forms]![SLIC_Miles]![TxtDistrict] _
& "'"

This doesn't:
DBS.Execute "INSERT INTO SLIC_Trips " _
& "Select * " _
& "From [SLIC_Trips_All] " _
& "Where SLIC_Trips_All.District=" & [Forms]![SLIC_Miles]![TxtDistrict] _
& " AND SLIC_Trips_All.Date=" & " 12/01/" & [Forms]![SLIC_Miles]![TxtYear] _
& "'"

Thanks in advance to taking a look.
 
Text fields need quotes and date fields need hash marks (#). Dates need to be either month, day, year or year, month, day.

[tt]DBS.Execute "INSERT INTO SLIC_Trips " _
& "Select * " _
& "From [SLIC_Trips_All] " _
& "Where SLIC_Trips_All.District='" & [Forms]![SLIC_Miles]![TxtDistrict] _
& "' AND SLIC_Trips_All.Date=#" & "12/01/" & [Forms]![SLIC_Miles]![TxtYear] _
& "#"[/tt]

It seems a little odd that miles are text: number field do not require delimiters.
 
Remou- Thanks, worked like a charm. Just proves how there is still to learn. The naming convention is my "denormalized" way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top