TRANSFORM Count(t_date.ftime) AS Sumftime
SELECT t_date.gh
FROM t_date
GROUP BY t_date.gh
PIVOT t_date.fdate;
What i'm doing is count the number of clocking per points number. My problem is if there is no clocking for one date, it will not show this date in the query.
So i will only have several dates in a month instead of full days and months.Is there a work around for this?
To force the column headings to appear in a crosstab query you need to populate the columns headings property in the column column. Handy if you are grouping by month, hard work if doing it by date. If you are up on VBA you could code the column heading prior to running the query.
To force the column headings to appear in a crosstab query you need to populate the columns headings property in the column column. Handy if you are grouping by month, hard work if doing it by date. If you are up on VBA you could code the column heading prior to running the query.
The problem with crosstabs is columns are variable depending on the presence of data unless you can force the date in via an external table with all the dates you require and link into t_date and see what's there. Its a bit like going fishing.
The easiest way is to run a procedure prior to calling the query to set the column headings for your crosstab.
Lets assume we have picked a particular month, say December.
We know the name of the month
We know that there will be a maximum number of 31 days in the month
Code:
Function GetDaysInMonth(AnyMonth As String) As String
Dim dtm as Date
Dim cHeadings As String
dtm = #01-" & AnyMonth & "-" Year(Date) & # ' First day of chosen month
For X = 1 To 32
If Month(dtm) <> AnyMonth Then
Exit For
End If
cHeadings = cHeadings & Chr(34) & Day(dtm) & Chr(34) & ","
dtm = DateAdd("d",1,dtm) ' increment date by one day
Next
'So what we have now is "1","2","3",etc,"31",
'Now we drop the final comma
cHeadings = Left(cHeadings,Len(cHeadings)-1)
Next we encompass it in an In statement
cHeadings = " In(" & cHeadings & ")"
GetDaysInMonth = cHeadings
End Function
Finally what we need to do now is insert this into the sql statement for the query we are about to run.
So we call the following function with two arguments
a) then month
b) the name of the crosstab query
Code:
Function UpdateColumnHeadings(AnyMonth As String, AnyQuery As String)
Dim Headings as String
'Create the headings
Headings = GetDaysInMonth(AnyMonth)
Dim dbsCurrent As Database
Dim qryTest As QueryDef
Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs(AnyQuery)
'Update the query sql
qryTest.SQL = Replace(qryTest.Sql,";",Headings & ";")
End Function
We have now tagged the column headings onto the end of the sql statement (After the PIVOT line)
To check it has worked design the query and look at the column headings property under the field supplying the days of the month.
now run the query.
You may need to tweek it but in essense this is how to do it.
The problem with crosstabs is columns are variable depending on the presence of data unless you can force the date in via an external table with all the dates you require and link into t_date and see what's there. Its a bit like going fishing.
Ok,i've found out a probable solution from another forum but i still need some help to calculate total days for each month.The file is included in the attachment...
Jan - 31
Feb - 28 or 29
Mar - 31
Apr - 30
May - 31
June - 30
July - 31
Aug - 31
Sept - 30
Oct - 31
Nov - 30
Dec - 31
Do i need to create a separate table for days or write an algorithm to calculate the different days in VBA?
My report will be based on month of year.Something like this :
[LIST=1]
[*] SELECT qryFlatCalendar.dteDate
[*] FROM qryFlatCalendar
[*] WHERE (((qryFlatCalendar.dteDate)<=#1/31/2008# And (qryFlatCalendar.dteDate)>=#1/1/2008#));
[*]
[/LIST]
I've tried this one... but not possible...
Code:
[LIST=1]
[*] SELECT qryFlatCalendar.dteDate
[*] FROM qryFlatCalendar
[*] WHERE (qryFlatCalendar.dteDate) <= #31-01-(Forms!monthly_rapport!combo10)#;
[*]
[/LIST]
I wanted the possibility to change the year or date using combo box, hopefully someone could guide me.