Skc,
How did you do it? To make a union query, you start to make a new query in
design view, add no table to the query and switch to SQL view, where you
actually type the SQL expression for it. Is this what you did? Did you get
the table and field names right? It could be that a fieldname is wrong in
the first SELECT statement, so it doesn't return any records. If you can't
find and fix the problem, post back the SQL expression in your query and the
actual table and field names for help.
HTH,
Nikos
Skc said:
Hi
Can you explain your Union Query. I have applied it, and all my EventTime
fields are Off.
skc
:
Skc,
I've done something similar in the past; the logic involved a union query
and some VBA code. The Union query is something like:
SELECT PhoneLog.Start As EventTime, "On" AS Event
FROM tblPhoneLog
UNION SELECT [Start]+[Duration] AS [End], "Off" As Event
FROM tblPhoneLog
This will return line on-and-offs as independent events, like:
EventTime Event
27/10/04 09:01:00 On
27/10/04 09:02:00 On
27/10/04 09:02:33 Off
27/10/04 09:10:22 Off
as per your example.
Now, the code opens this query (ordered on EventTime) as a
recordset,
and
goes through the records. As it does so, it checks the value of
field
Event
on each record, and increases the number of an active line counter
by
one
for every On, and decreases it by one for every Off. Each time it
finds
an
On it compares the current value of active lines to another variable (max
active lines) and replaces it if greater. So, at the end of the loop through
the records, the latter holds the max number of active lines. The
code
would
look something like:
Sub Count_Max_Active_Lines()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim MaxLines As Long
Dim ConcLines As Long
Dim strSQL As String
ConcLines = 0
MaxLines = 0
Set db = CurrentDb
strSQL = "SELECT * FROM qryEvents ORDER BY EventTime"
'you can impose some filter on strSQL, or on the original Union query
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Do Until rst.EOF
If rst.Fields(1) = "On" Then
ConcLines = ConcLines + 1
If ConcLines > MaxLines Then
MaxLines = ConcLines
End If
Else
ConcLines = ConcLines - 1
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Debug.Print MaxLines
'code to do what you want with MaxLines
End Sub
Note: you need a proper DAO reference for this code to run.
HTH,
Nikos
I have an Access table (Access 2000) that contains phonelogs.
These
logs
are
compiled with Date (dd/mm/yyyy), Time of Day (hh:mm:ss), Start of
conversation (dd/mm/yyyy hh:mm:ss), Duration (hh:mm:ss).
I want to know how many lines (we have 10) are occupied in a particular
timeslot. For instance, if PersonA started his conversation at 27/10/2004
09:01:00 to 09:02:33 and PersonB at 27/10/2004 09:02:00 to
09:10:22
then
they
occupied 2 lines for a brief moment as they times clashed.
How can I do these stats using SQL or programming please?
skc