M
mtorr2x
I have been tasked to create a db that has employees, charge numbers, and
hours worked per week. i am trying to generate a report that displays up to
5 weeks of summary data based on the work ending date.
I found a thread posted about a year ago called "dynamic crosstab A2002". I
have used this thread to create my report but i get a blank report. If I
ener in the absolute date in the Criteria of the crosstab query the report
does work as expected. But if i enter in
Between ([forms]![frm_NameData].[cbo_WEStartDate].[value]) And ([forms]!
[frm_NameData].[cbo_WEEndDate].[value])
I get the blank report.
i looked at the created query based off of the crosstab query and the SQL is:
SELECT Null AS Field0, Null AS Field1, Null AS Field2, Null AS Field3, Null
AS Field4, Null AS Field5, Null AS Field6, Null AS Field7, Null AS Field8,
Null AS Field9
FROM Crosstab_Name2;
Why am i getting Null values?
My code for the report is:
Option Compare Database
Option Explicit
Dim reportlabel(10) As String
_______________________________________________
Private Sub Report_Open(Cancel As Integer)
'DoCmd.Maximize
Dim i As Integer
For i = 0 To 9
reportlabel(i) = ""
Next i
Call CreateReportQuery
End Sub
__________________________________________
Sub CreateReportQuery()
On Error GoTo Err_CreateQuery
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Dim indexx As Integer
Dim FieldList As String
Dim strSQL As String
Dim i As Integer
Dim j As Field
Set db = CurrentDb
Set qdf = db.QueryDefs("Crosstab_Name2")
indexx = 0
For Each fld In qdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
FieldList = FieldList & "[" & fld.name & "] as Field" & indexx &
", "
reportlabel(indexx) = fld.name
End If
indexx = indexx + 1
Next fld
For i = indexx To 9
FieldList = FieldList & "null as Field" & i & ","
Next i
FieldList = Left(FieldList, Len(FieldList) - 1)
strSQL = "Select " & FieldList & " From Crosstab_Name2" & ";"
'MsgBox strSQL
db.QueryDefs.Delete "Crosstab_Report_Name2"
Set qdf = db.CreateQueryDef("Crosstab_Report_Name2", strSQL)
Exit_CreateQuery:
Exit Sub
Err_CreateQuery:
If Err.Number = 3265 Then '*** if the error is the query is missing
Resume Next '*** then skip the delete line and resume on
the next line
Else
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_CreateQuery
End If
End Sub
____________________________________________________________________________
Function FillLabel(LabelNumber As Integer) As String
FillLabel = Nz(reportlabel(LabelNumber), "")
End Function
My crosstab query SQL is:
PARAMETERS [forms]![frm_NameData].[cbo_WEStartDate].[value] DateTime, [forms]!
[frm_NameData].[cbo_WEEndDate].[value] DateTime;
TRANSFORM Sum([All Data Query].HOURS) AS SumOfHOURS
SELECT [All Data Query].Project, [All Data Query].Function, [Last Name]+", "+
[First Name] AS TheName, Sum([All Data Query].HOURS) AS [Total Of HOURS]
FROM [All Data Query]
WHERE ((([All Data Query].[Week Ending Date]) Between ([forms]![frm_NameData].
[cbo_WEStartDate].[value]) And ([forms]![frm_NameData].[cbo_WEEndDate].[value]
)))
GROUP BY [All Data Query].Project, [All Data Query].Function, [Last Name]+",
"+[First Name]
ORDER BY Format([Week Ending Date],"mm/dd/yy")
PIVOT Format([Week Ending Date],"mm/dd/yy");
hours worked per week. i am trying to generate a report that displays up to
5 weeks of summary data based on the work ending date.
I found a thread posted about a year ago called "dynamic crosstab A2002". I
have used this thread to create my report but i get a blank report. If I
ener in the absolute date in the Criteria of the crosstab query the report
does work as expected. But if i enter in
Between ([forms]![frm_NameData].[cbo_WEStartDate].[value]) And ([forms]!
[frm_NameData].[cbo_WEEndDate].[value])
I get the blank report.
i looked at the created query based off of the crosstab query and the SQL is:
SELECT Null AS Field0, Null AS Field1, Null AS Field2, Null AS Field3, Null
AS Field4, Null AS Field5, Null AS Field6, Null AS Field7, Null AS Field8,
Null AS Field9
FROM Crosstab_Name2;
Why am i getting Null values?
My code for the report is:
Option Compare Database
Option Explicit
Dim reportlabel(10) As String
_______________________________________________
Private Sub Report_Open(Cancel As Integer)
'DoCmd.Maximize
Dim i As Integer
For i = 0 To 9
reportlabel(i) = ""
Next i
Call CreateReportQuery
End Sub
__________________________________________
Sub CreateReportQuery()
On Error GoTo Err_CreateQuery
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Dim indexx As Integer
Dim FieldList As String
Dim strSQL As String
Dim i As Integer
Dim j As Field
Set db = CurrentDb
Set qdf = db.QueryDefs("Crosstab_Name2")
indexx = 0
For Each fld In qdf.Fields
If fld.Type >= 1 And fld.Type <= 8 Or fld.Type = 10 Then
FieldList = FieldList & "[" & fld.name & "] as Field" & indexx &
", "
reportlabel(indexx) = fld.name
End If
indexx = indexx + 1
Next fld
For i = indexx To 9
FieldList = FieldList & "null as Field" & i & ","
Next i
FieldList = Left(FieldList, Len(FieldList) - 1)
strSQL = "Select " & FieldList & " From Crosstab_Name2" & ";"
'MsgBox strSQL
db.QueryDefs.Delete "Crosstab_Report_Name2"
Set qdf = db.CreateQueryDef("Crosstab_Report_Name2", strSQL)
Exit_CreateQuery:
Exit Sub
Err_CreateQuery:
If Err.Number = 3265 Then '*** if the error is the query is missing
Resume Next '*** then skip the delete line and resume on
the next line
Else
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_CreateQuery
End If
End Sub
____________________________________________________________________________
Function FillLabel(LabelNumber As Integer) As String
FillLabel = Nz(reportlabel(LabelNumber), "")
End Function
My crosstab query SQL is:
PARAMETERS [forms]![frm_NameData].[cbo_WEStartDate].[value] DateTime, [forms]!
[frm_NameData].[cbo_WEEndDate].[value] DateTime;
TRANSFORM Sum([All Data Query].HOURS) AS SumOfHOURS
SELECT [All Data Query].Project, [All Data Query].Function, [Last Name]+", "+
[First Name] AS TheName, Sum([All Data Query].HOURS) AS [Total Of HOURS]
FROM [All Data Query]
WHERE ((([All Data Query].[Week Ending Date]) Between ([forms]![frm_NameData].
[cbo_WEStartDate].[value]) And ([forms]![frm_NameData].[cbo_WEEndDate].[value]
)))
GROUP BY [All Data Query].Project, [All Data Query].Function, [Last Name]+",
"+[First Name]
ORDER BY Format([Week Ending Date],"mm/dd/yy")
PIVOT Format([Week Ending Date],"mm/dd/yy");