473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to display individual and summary records in a query?

Hello all,
This is my first post, please let me know if I've missed any relevant data or guidelines.

I'm using Access 2003 for the database and Excel 2003 for the reporting to avoid having everyone reading the reports install the snapshot viewer. I'm also porting this application to SQL Server/ASP.NET eventually, and there is not a way to install reporting services on the server, so my hope is to use Excel there as well.

I'm using two queries, one to get the relevant data and another using Group By to count and summarize the data. It's a student database and I'm getting the name, day attended, and hours attended for each student. What I want to wind up with I could do with Access reports, but I can't figure out how to do it in VBA with the queries.

The end result I'm looking for would be something like:
Student 1 10/1/2008 5 hrs
Student 1 10/2/2009 2 hrs
Summary Student 1 2 days 7 hrs

Student 2 10/1/2008 2 hrs
Student 2 10/2/2008 3 hrs
Summary Student 2 2 days 5 hrs.

Here are the queries:
Detail Query: [SQL]
SELECT [tblPersonData].[FirstName] & " " & [tblPersonData].[LastName] AS Name, DateValue([LogInTime]) AS DayAttended, DateDiff("n",[LogInTime],[LogOutTime])/60 AS HoursAttended
FROM tblPersonData INNER JOIN tblPersonTimeLog ON tblPersonData.PersonID = tblPersonTimeLog.PersonId
WHERE (((tblPersonData.Site)=[forms]![fdlgAttendanceReport]![cboSite]) AND ((tblPersonData.Role)="Student") AND ((tblPersonTimeLog.LogInTime) Between ([forms]![fdlgAttendanceReport]![txtStart]) And (DateValue([forms]![fdlgAttendanceReport]![txtEnd]) & " 11:59:59 PM")))
ORDER BY [tblPersonData].[FirstName] & " " & [tblPersonData].[LastName], DateValue([LogInTime]);
[/SQL]

Summary Query: [SQL]
SELECT [qselAttendanceReport-detail].Name, Count([qselAttendanceReport-detail].DayAttended) AS CountOfDayAttended, Sum([qselAttendanceReport-detail].HoursAttended) AS SumOfHoursAttended
FROM [qselAttendanceReport-detail]
GROUP BY [qselAttendanceReport-detail].Name
ORDER BY [qselAttendanceReport-detail].Name;
[/SQL]

After creating all the objects and a recordset from a query, I use the following code to kick the data out to the Excel worksheet (wks) I created like so:
Expand|Select|Wrap|Line Numbers
  1.    Do Until rst.EOF
  2.       iFld = 0
  3.       lRecords = lRecords + 1
  4.       Me.lblMsg.Caption = "Exporting record #" & lRecords & " to " & sOutput
  5.       Me.Repaint
  6.  
  7.       For iCol = cStartColumn To cStartColumn + (rst.Fields.Count - 1)
  8.          wks.Cells(iRow, iCol) = rst.Fields(iFld)
  9.  
  10.          If InStr(1, rst.Fields(iFld).Name, "Date") > 0 Then
  11.             wks.Cells(iRow, iCol).NumberFormat = "mm/dd/yyyy"
  12.          End If
  13.  
  14.          wks.Cells(iRow, iCol).WrapText = False
  15.          iFld = iFld + 1
  16.       Next
  17.  
  18.       wks.Rows(iRow).EntireRow.AutoFit
  19.       iRow = iRow + 1
  20.       rst.MoveNext
  21.    Loop
  22.  
I'm guessing I need to write out the detail records, and somehow when the student name changes, write out the summary, maybe with domain aggregate functions, but this is as far as I've been able to get. Right now I'm creating two worksheets, one with detail data, the other with summary data. Pretty inelegant.

Thanks if
Nov 13 '08 #1
1 2429
PianoMan64
374 Expert 256MB
Hello all,
This is my first post, please let me know if I've missed any relevant data or guidelines.

I'm using Access 2003 for the database and Excel 2003 for the reporting to avoid having everyone reading the reports install the snapshot viewer. I'm also porting this application to SQL Server/ASP.NET eventually, and there is not a way to install reporting services on the server, so my hope is to use Excel there as well.

I'm using two queries, one to get the relevant data and another using Group By to count and summarize the data. It's a student database and I'm getting the name, day attended, and hours attended for each student. What I want to wind up with I could do with Access reports, but I can't figure out how to do it in VBA with the queries.

The end result I'm looking for would be something like:
Student 1 10/1/2008 5 hrs
Student 1 10/2/2009 2 hrs
Summary Student 1 2 days 7 hrs

Student 2 10/1/2008 2 hrs
Student 2 10/2/2008 3 hrs
Summary Student 2 2 days 5 hrs.

Here are the queries:
Detail Query: [SQL]
SELECT [tblPersonData].[FirstName] & " " & [tblPersonData].[LastName] AS Name, DateValue([LogInTime]) AS DayAttended, DateDiff("n",[LogInTime],[LogOutTime])/60 AS HoursAttended
FROM tblPersonData INNER JOIN tblPersonTimeLog ON tblPersonData.PersonID = tblPersonTimeLog.PersonId
WHERE (((tblPersonData.Site)=[forms]![fdlgAttendanceReport]![cboSite]) AND ((tblPersonData.Role)="Student") AND ((tblPersonTimeLog.LogInTime) Between ([forms]![fdlgAttendanceReport]![txtStart]) And (DateValue([forms]![fdlgAttendanceReport]![txtEnd]) & " 11:59:59 PM")))
ORDER BY [tblPersonData].[FirstName] & " " & [tblPersonData].[LastName], DateValue([LogInTime]);
[/SQL]

Summary Query: [SQL]
SELECT [qselAttendanceReport-detail].Name, Count([qselAttendanceReport-detail].DayAttended) AS CountOfDayAttended, Sum([qselAttendanceReport-detail].HoursAttended) AS SumOfHoursAttended
FROM [qselAttendanceReport-detail]
GROUP BY [qselAttendanceReport-detail].Name
ORDER BY [qselAttendanceReport-detail].Name;
[/SQL]

After creating all the objects and a recordset from a query, I use the following code to kick the data out to the Excel worksheet (wks) I created like so:
Expand|Select|Wrap|Line Numbers
  1.    Do Until rst.EOF
  2.       iFld = 0
  3.       lRecords = lRecords + 1
  4.       Me.lblMsg.Caption = "Exporting record #" & lRecords & " to " & sOutput
  5.       Me.Repaint
  6.  
  7.       For iCol = cStartColumn To cStartColumn + (rst.Fields.Count - 1)
  8.          wks.Cells(iRow, iCol) = rst.Fields(iFld)
  9.  
  10.          If InStr(1, rst.Fields(iFld).Name, "Date") > 0 Then
  11.             wks.Cells(iRow, iCol).NumberFormat = "mm/dd/yyyy"
  12.          End If
  13.  
  14.          wks.Cells(iRow, iCol).WrapText = False
  15.          iFld = iFld + 1
  16.       Next
  17.  
  18.       wks.Rows(iRow).EntireRow.AutoFit
  19.       iRow = iRow + 1
  20.       rst.MoveNext
  21.    Loop
  22.  
I'm guessing I need to write out the detail records, and somehow when the student name changes, write out the summary, maybe with domain aggregate functions, but this is as far as I've been able to get. Right now I'm creating two worksheets, one with detail data, the other with summary data. Pretty inelegant.

Thanks if

Hello Randy,

I guess my question in all of that is, what is it that you want to know how to do?

It seems that you have a good system going, but it is a little over-kill on the exporting to Excel when you have the ability within access to create reports that would provide all the information that you need.

If it is simply about security of student information, there are more than plenty of options that you could make use of the Workgroup file within MS Access that would allow you to create user names and passwords for each student, and give then a custom form that they would allow them to look at there information only and not any one else.

If you need examples on how to do that, there is an Microsoft Artical on that very subject.

http://support.microsoft.com/kb/305542
http://support.microsoft.com/kb/289885/
http://support.microsoft.com/support/access/content/secfaq.asp?SD=gn&LN=en-us&gssnb=1
Nov 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jerome | last post by:
Hi, I've got the following problem: I want my ASP page to display a certain number (based on a COUNT query), it works fine if the result is at least 1! If there are no records to be counted...
6
by: geronimo_me | last post by:
I have 20 queries that compare fields in one table with fields in another table - the query results are the records that do not match in Table1 and Table2. ie Table1 DOB 28/02/78 Table2 DOB...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
19
by: octangle | last post by:
This code is attempting to find records that have a RegJrnID that does not occur more than one time in the table. The reason that I want to find records with non-duplicated RegJrnID values is to...
5
by: bruce24444 | last post by:
What I have is a database which tracks assigned files to a certain people which is generated by a form and then recorded into a table. Table are as follows “Staff” “Loss_Type” and...
1
by: bruce24444 | last post by:
First of all I'm new to the forum and am working on my first database. So far I think I've done not too bad but have hit a stumbling block for which I'm not sure how to get around. What I have is...
4
by: rn5a | last post by:
A MS-Access DB has 3 tables - Teacher, Class & TeacherClass. The Teacher table has 2 columns - TeacherID & TeacherName (TeacherID being the primary key). The Class table too has 2 columns - ClassID...
7
by: imtmub | last post by:
I have 3 table for Purchase Order from ERP Database Tables: POD=Purchase order Details(this table has Require Qty field) POR=Purchase Order Receive (This table has RequireQty and ReceiptQty...
12
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.