J
James Stephens
This is a follow up on a calender question that I posted yesterday under
queries, but I put it into a new thread because I am going a different route
with this (I think). As a brief description this is what I have set-up. I
have a table with 5 fields: StartDate, EndDate, Requested, Approved, Denied.
This is for leave requests. I am trying to get the calender form that I
built to show this data. The calender is built and works. If you need to
see it I can send it to you. It will put the values into labels under each
date. What I need to do is take the current table and get it into a format
of: Date, Requested, Approved, Denied, so that I can sum up for each date,
how much leave is requested and its status. I have two querys that work
together to get this. Here are the Sql of each of them:
PARAMETERS EnterDate DateTime;
SELECT IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Requested),0) AS Requested,
IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Approved),0) AS Approved,
IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Denied),0) AS Denied
FROM Calender1;
This will prompt for a date. And then return all leave where that date
falls between the start and end dates. Then I use this to get the sum.
SELECT DISTINCTROW Sum([Calender1 Query].Requested) AS Requested,
Sum([Calender1 Query].Approved) AS Approved, Sum([Calender1 Query].Denied) AS
Denied
FROM [Calender1 Query];
What I need to find out how to do is pass the value from the VBA code that
creates the calender to the query as the [EnterDate]. The calender code has
a loop that creates the calender, and in that I will have the date value for
each day, which I could then pass to this query and get the three values to
put into the Calender. But I can't figure out how to do this. I could
really use some help here. I don't know if I need to put the SQL directly
into VBA or just pass the value to the query from VBA, and I am not sure
exactly how to do either.
Here is the part of the calender code where the value needs to get assigned.
firstDate = dateVar - Day(dateVar) + 1
thisDate = firstDate - Weekday(firstDate) + 1
For dayCounter = 1 To 42
ctlName = "CalText" & dayCounter
Set ctl = Controls(ctlName)
ctl.Caption = ""
ctl.Tag = thisDate
thisDate = thisDate + 1
Next dayCounter
firstDate = dateVar - Day(dateVar) + 1
thisDate = firstDate - Weekday(firstDate) + 1
For dayCounter = 1 To 42
ctlName = "CalText" & dayCounter
Set ctl = Controls(ctlName)
ctl.Caption = <=== Here is where I need to assign the values from
the query
ctl.Tag = thisDate
End If
If thisDate = Date Then
ctl.BackColor = Red
ElseIf Month(thisDate) = Month(dateVar) Then
ctl.BackColor = White
Else
ctl.BackColor = Grey
End If
thisDate = thisDate + 1
Next dayCounter
Any help would be greatly apprecited as I know I am close on this one. If
you need any other information to assist with this let me know.
Thanks,
James Stephens
queries, but I put it into a new thread because I am going a different route
with this (I think). As a brief description this is what I have set-up. I
have a table with 5 fields: StartDate, EndDate, Requested, Approved, Denied.
This is for leave requests. I am trying to get the calender form that I
built to show this data. The calender is built and works. If you need to
see it I can send it to you. It will put the values into labels under each
date. What I need to do is take the current table and get it into a format
of: Date, Requested, Approved, Denied, so that I can sum up for each date,
how much leave is requested and its status. I have two querys that work
together to get this. Here are the Sql of each of them:
PARAMETERS EnterDate DateTime;
SELECT IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Requested),0) AS Requested,
IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Approved),0) AS Approved,
IIf(Calender1!StartDateCode<=[EnterDate] And
Calender1!EndDateCode>=[EnterDate],Abs(Calender1!Denied),0) AS Denied
FROM Calender1;
This will prompt for a date. And then return all leave where that date
falls between the start and end dates. Then I use this to get the sum.
SELECT DISTINCTROW Sum([Calender1 Query].Requested) AS Requested,
Sum([Calender1 Query].Approved) AS Approved, Sum([Calender1 Query].Denied) AS
Denied
FROM [Calender1 Query];
What I need to find out how to do is pass the value from the VBA code that
creates the calender to the query as the [EnterDate]. The calender code has
a loop that creates the calender, and in that I will have the date value for
each day, which I could then pass to this query and get the three values to
put into the Calender. But I can't figure out how to do this. I could
really use some help here. I don't know if I need to put the SQL directly
into VBA or just pass the value to the query from VBA, and I am not sure
exactly how to do either.
Here is the part of the calender code where the value needs to get assigned.
firstDate = dateVar - Day(dateVar) + 1
thisDate = firstDate - Weekday(firstDate) + 1
For dayCounter = 1 To 42
ctlName = "CalText" & dayCounter
Set ctl = Controls(ctlName)
ctl.Caption = ""
ctl.Tag = thisDate
thisDate = thisDate + 1
Next dayCounter
firstDate = dateVar - Day(dateVar) + 1
thisDate = firstDate - Weekday(firstDate) + 1
For dayCounter = 1 To 42
ctlName = "CalText" & dayCounter
Set ctl = Controls(ctlName)
ctl.Caption = <=== Here is where I need to assign the values from
the query
ctl.Tag = thisDate
End If
If thisDate = Date Then
ctl.BackColor = Red
ElseIf Month(thisDate) = Month(dateVar) Then
ctl.BackColor = White
Else
ctl.BackColor = Grey
End If
thisDate = thisDate + 1
Next dayCounter
Any help would be greatly apprecited as I know I am close on this one. If
you need any other information to assist with this let me know.
Thanks,
James Stephens