473,385 Members | 1,736 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,385 software developers and data experts.

SQL in Access Report

I have one table used to maintain information on Service Events.
Each record contains a Repair, Maint, and Battery checkbox
(bound/boolean). Any one of these fields may be checked or left empty.
Ex. REPAIR=True, MAINT=False, BATTERY=True

I want to generate ONE report that lists all the REPAIRS, then lists
all the MAINT, and then lists all the BATTERY events. One group after
the other in the same report. Because (ex. REPAIR and BATTERY) may
both be true in the same record, the record will appear 2 times in the
report, once in the REPAIR group and once in the BATTERY group.

I am not sure how to approach this. I'm new to SQL. I' m using MS
AccessSQL.

I Tried the following code, but the results are not sorting properly
and not grouped.

SELECT * FROM [TABLE1] WHERE [REPAIR]
UNION ALL
SELECT * FROM [TABLE1] WHERE [MAINT]
UNION ALL
SELECT * FROM [TABLE1] WHERE [BATTERY]

Apr 25 '06 #1
4 4591
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You don't need a UNION query, just a regular SELECT

(Access SQL syntax)

SELECT IIf(repair=True,"Repair",
IIf(battery=True,"Battery",
IIf(maint=True,"Maint","Unknown") As GroupByThis,
repair,
maint,
battery,
<other columns>
FROM table1
WHERE <some criteria>

Set up your report using the Grouping/Sorting dialog box

(menu bar: View > Sorting and Grouping)

Select the GroupByThis column in the Field/Expression column of the
dialog box. Set the Group Header to Yes. Place the GroupByThis column
in the Group Header column. If you want to put totals for each
grouping, set the Group Footer to Yes and set up =Sum() Text Boxes.

Now the report is set up to group each GroupByThis value.

For more info on creating report groups see the Access Help articles
under table of contents heading

Reports and Report Snapshots
Sorting and Grouping Records in a Report

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRE6sgoechKqOuFEgEQI3YACeK41dgagIW4yD/7FgbdGQXTPX3jUAoKzC
g5e9onkszM/TwkfuX0UVVC7H
=SF3w
-----END PGP SIGNATURE-----
Ap******@gmail.com wrote:
I have one table used to maintain information on Service Events.
Each record contains a Repair, Maint, and Battery checkbox
(bound/boolean). Any one of these fields may be checked or left empty.
Ex. REPAIR=True, MAINT=False, BATTERY=True

I want to generate ONE report that lists all the REPAIRS, then lists
all the MAINT, and then lists all the BATTERY events. One group after
the other in the same report. Because (ex. REPAIR and BATTERY) may
both be true in the same record, the record will appear 2 times in the
report, once in the REPAIR group and once in the BATTERY group.

I am not sure how to approach this. I'm new to SQL. I' m using MS
AccessSQL.

I Tried the following code, but the results are not sorting properly
and not grouped.

SELECT * FROM [TABLE1] WHERE [REPAIR]
UNION ALL
SELECT * FROM [TABLE1] WHERE [MAINT]
UNION ALL
SELECT * FROM [TABLE1] WHERE [BATTERY]

Apr 25 '06 #2
Thanks for the response.

I took your advice and tried the following code:

SELECT IIf([RPR]=True,"RPR",
IIf([MNT]=True,"MNT",
IIf([BAT]=True,"BAT","Unknown"))) AS GroupByThis,
[RPR],
[BAT],
[MNT],
*
FROM [T-SERVICE];

The repairs have grouped just fine, but the battery and maint will only
group with records that are not already displayed in the repairs group.

Any further advice?

Apr 26 '06 #3
Ap******@gmail.com wrote:
Thanks for the response.

I took your advice and tried the following code:

SELECT IIf([RPR]=True,"RPR",
IIf([MNT]=True,"MNT",
IIf([BAT]=True,"BAT","Unknown"))) AS GroupByThis,
[RPR],
[BAT],
[MNT],
*
FROM [T-SERVICE];

The repairs have grouped just fine, but the battery and maint will only
group with records that are not already displayed in the repairs group.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may have to go back to your original UNION query, with the addition
of a GroupByThis column. E.g.:

SELECT "RPR" As GroupByThis, *
FROM [T-Service]
WHERE [RPR] = True
UNION
SELECT "BAT" As GroupByThis, *
FROM [T-Service]
WHERE [BAT] = True
UNION
SELECT "MNT" As GroupByThis, *
FROM [T-Service]
WHERE [MNT] = True
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRE7ZwIechKqOuFEgEQKwrwCg4/+EDv8jV+47+CAGLaCoH/WDcCMAni3n
Dx9Xa1Cla3dw3zNvYjxuoxXA
=45Cm
-----END PGP SIGNATURE-----
Apr 26 '06 #4
THAT WORKED !!!

Thankyou Very Much. I spent a long time on this one.
Your advice was right on target. Someone else also had
recommended a similar solution in another group, but it just
took time to sink in.

Thanks Again :)

Apr 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
20
by: John | last post by:
Hi, I've recently upgraded from Access 97 to Access 2002 & the performance basically stinks. I have tried the following items listed below but it has only had a minor impact: 1) Upgraded Jet...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
6
by: Bob Alston | last post by:
I am looking for Access reporting add-in that would be easy to use by end users. My key focus is on selection criteria. I am very happy with the Access report writer capabilities. As far as...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.