Hi There,
Please can someone help with the code below. My issue is to do with the formating of pulling an entered date from Excel and passing it as a parameter into the sql string. If I hard code sql with the dates no problem, but it isn't accepting the parameters from excel. Any ideas?
cndbs.Open strconn
Dim rsdbs As ADODB.Recordset
Set rsdbs = New ADODB.Recordset
Set curSheet = ActiveWorkbook.Worksheets("Sheet2")
With curSheet
strFrom = VBA.Format(curSheet.Range("E1").Value, "dd mmm yyyy")
strTo = VBA.Format(curSheet.Range("F1").Value, "dd mmm yyyy")
End With
strText = "SELECT projects.PRJ_ID AS 'Hours_By_Project', projects.PRJ_NAME AS ' ',Sum(timesheets.TST_DURATION) AS 'Hours' FROM CampusDevelopment.dbo.view__activities activities, CampusDevelopment.dbo.view__projects projects, CampusDevelopment.dbo.View__timesheets timesheets WHERE projects.PRJ_ID = timesheets.PRJ_ID And timesheets.ACT_ID = activities.ACT_ID And (timesheets.TST_DATE >= '" & strFrom & " ' And timesheets.TST_DATE < ' " & strTo & " ' And (projects.PRJ_ID Like 'BPPIT%')) GROUP BY projects.PRJ_ID, projects.PRJ_NAME"
Cheers
Sam
Please can someone help with the code below. My issue is to do with the formating of pulling an entered date from Excel and passing it as a parameter into the sql string. If I hard code sql with the dates no problem, but it isn't accepting the parameters from excel. Any ideas?
cndbs.Open strconn
Dim rsdbs As ADODB.Recordset
Set rsdbs = New ADODB.Recordset
Set curSheet = ActiveWorkbook.Worksheets("Sheet2")
With curSheet
strFrom = VBA.Format(curSheet.Range("E1").Value, "dd mmm yyyy")
strTo = VBA.Format(curSheet.Range("F1").Value, "dd mmm yyyy")
End With
strText = "SELECT projects.PRJ_ID AS 'Hours_By_Project', projects.PRJ_NAME AS ' ',Sum(timesheets.TST_DURATION) AS 'Hours' FROM CampusDevelopment.dbo.view__activities activities, CampusDevelopment.dbo.view__projects projects, CampusDevelopment.dbo.View__timesheets timesheets WHERE projects.PRJ_ID = timesheets.PRJ_ID And timesheets.ACT_ID = activities.ACT_ID And (timesheets.TST_DATE >= '" & strFrom & " ' And timesheets.TST_DATE < ' " & strTo & " ' And (projects.PRJ_ID Like 'BPPIT%')) GROUP BY projects.PRJ_ID, projects.PRJ_NAME"
Cheers
Sam