When I use ADO CurrentProject.Connection this is what I use.
strSQL4 = "SELECT StartTons, StartTonsAdjust, " _
& "SampleTons, ShipmentTons, EndTons, " _
& "ShiftTonsAdjust, UserID " _
& "FROM tbl_Prod_Shift " _
& "WHERE (((ShiftDate)=#" & myvardate & "#) " _
& "AND ((Shift)=" & shft & ") AND ((Storage)=" & stor &
")); "
When I pass the SQL directly to SQL server using ADO OLEDB then this is what
I use.
strSQL = "SELECT tbl_coal_perf.fld_Date, tbl_coal_perf.fld_Crushed,
" _
& "tbl_coal_perf.fld_plan_tons, tbl_coal_perf.fld_truck_hours "
_
& "FROM tbl_coal_perf " _
& "INNER JOIN lst_supv ON tbl_coal_perf.fld_Supv_Coal =
lst_supv.ID " _
& "WHERE (tbl_coal_perf.fld_Date " _
& "BETWEEN CONVERT(DATETIME, '" & date1 & "', 102) AND " _
& "CONVERT(DATETIME, '" & date2 & "', 102)) AND " _
& "(lst_supv.fld_name = '" & shtname(j) & "') "
All date variables (myvardate, date1 and date2) are dimensioned as string.
To avoid confusion I always Dim dates as string and then delimit them
according to what the connection expects.
--
Regards,
Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
:
| Project details: Access front End
| SQL Back End
| Why in Access Programming, sometimes using " # " (Pound sign) as date
| deliminator works and sometimes have to use " ' "(Single quote)?
| How can we decied when to use specific one?