E
EAB1977
Hello everyone,
This SQL statement below is confusing the heck out of me.
I built my query from the query builder in Access(97). I then went to
the SQL view, copied it, and pasted this into a VBA module. It returns
records in the query, but returns zero records when I try to access
this from VBA code. I have tried using just the query, but that gives
me a error.
Here's the code I have so far:
Private Sub cmdExport_Click()
Dim objExcel As Object, dbs As DAO.Database, rst As DAO.Recordset
On Error GoTo cmdExport_ErrHandler
Set objExcel = CreateObject("Excel.Application")
Set dbs = CurrentDb
With objExcel
.ScreenUpdating = True
.Visible = True
.DisplayAlerts = True
.Workbooks.Open "J:\QA\Database\CQAAnalysis\Dev 6-3-2008\CQA
Analysis Test Time Report.xls"
.Range("A2").select
Set rst = dbs.OpenRecordset("SELECT Plant.PlantName,
AnalysisTestGroup.TestID, qryAnalysisCount.Sets," _
& " AnalysisTestGroup.StartDate,
AnalysisTestGroup.StartTime, AnalysisTestGroup.EndDate," _
& " AnalysisTestGroup.EndTime, tblEmployee.UserName,
Sum(AnalysisTestGroupTime.Time) AS TestTime" _
& " FROM (tblEmployee INNER JOIN (qryAnalysisCount INNER
JOIN (Plant INNER JOIN AnalysisTestGroup ON" _
& " Plant.PlantCode = AnalysisTestGroup.PlantCode) ON
qryAnalysisCount.TestID = AnalysisTestGroup.TestID)" _
& " ON tblEmployee.EmployeeID =
AnalysisTestGroup.TestPerson) INNER JOIN AnalysisTestGroupTime ON" _
& " AnalysisTestGroup.TestID =
AnalysisTestGroupTime.TestID" _
& " WHERE (((AnalysisTestGroup.EndDate) Is Not Null) AND
((AnalysisTestGroup.StartDate)>=" & [Forms]![EricsForm]![txtStartDate]
& ") AND ((AnalysisTestGroup.EndDate)<=" & [Forms]![EricsForm]!
[txtEndDate] & "))" _
& " GROUP BY Plant.PlantName, AnalysisTestGroup.TestID,
qryAnalysisCount.Sets, AnalysisTestGroup.StartDate," _
& " AnalysisTestGroup.StartTime,
AnalysisTestGroup.EndDate, AnalysisTestGroup.EndTime," _
& " tblEmployee.UserName ORDER BY tblEmployee.UserName,
AnalysisTestGroup.StartDate, AnalysisTestGroup.EndDate")
MsgBox rst.RecordCount
End With
Exit Sub
cmdExport_ErrHandler:
Call LogError(Err.Number, Err.Description, Me.FormName, , True)
End Sub
Any help would be appreciated. Thanks!
This SQL statement below is confusing the heck out of me.
I built my query from the query builder in Access(97). I then went to
the SQL view, copied it, and pasted this into a VBA module. It returns
records in the query, but returns zero records when I try to access
this from VBA code. I have tried using just the query, but that gives
me a error.
Here's the code I have so far:
Private Sub cmdExport_Click()
Dim objExcel As Object, dbs As DAO.Database, rst As DAO.Recordset
On Error GoTo cmdExport_ErrHandler
Set objExcel = CreateObject("Excel.Application")
Set dbs = CurrentDb
With objExcel
.ScreenUpdating = True
.Visible = True
.DisplayAlerts = True
.Workbooks.Open "J:\QA\Database\CQAAnalysis\Dev 6-3-2008\CQA
Analysis Test Time Report.xls"
.Range("A2").select
Set rst = dbs.OpenRecordset("SELECT Plant.PlantName,
AnalysisTestGroup.TestID, qryAnalysisCount.Sets," _
& " AnalysisTestGroup.StartDate,
AnalysisTestGroup.StartTime, AnalysisTestGroup.EndDate," _
& " AnalysisTestGroup.EndTime, tblEmployee.UserName,
Sum(AnalysisTestGroupTime.Time) AS TestTime" _
& " FROM (tblEmployee INNER JOIN (qryAnalysisCount INNER
JOIN (Plant INNER JOIN AnalysisTestGroup ON" _
& " Plant.PlantCode = AnalysisTestGroup.PlantCode) ON
qryAnalysisCount.TestID = AnalysisTestGroup.TestID)" _
& " ON tblEmployee.EmployeeID =
AnalysisTestGroup.TestPerson) INNER JOIN AnalysisTestGroupTime ON" _
& " AnalysisTestGroup.TestID =
AnalysisTestGroupTime.TestID" _
& " WHERE (((AnalysisTestGroup.EndDate) Is Not Null) AND
((AnalysisTestGroup.StartDate)>=" & [Forms]![EricsForm]![txtStartDate]
& ") AND ((AnalysisTestGroup.EndDate)<=" & [Forms]![EricsForm]!
[txtEndDate] & "))" _
& " GROUP BY Plant.PlantName, AnalysisTestGroup.TestID,
qryAnalysisCount.Sets, AnalysisTestGroup.StartDate," _
& " AnalysisTestGroup.StartTime,
AnalysisTestGroup.EndDate, AnalysisTestGroup.EndTime," _
& " tblEmployee.UserName ORDER BY tblEmployee.UserName,
AnalysisTestGroup.StartDate, AnalysisTestGroup.EndDate")
MsgBox rst.RecordCount
End With
Exit Sub
cmdExport_ErrHandler:
Call LogError(Err.Number, Err.Description, Me.FormName, , True)
End Sub
Any help would be appreciated. Thanks!