Author |
Message |
Scorchedbee =GCHQ=
|
Post subject: working out %ages in acces? Posted: Sun Apr 09, 2006 9:06 pm |
|
|
I Burn Insects |
|
Joined: Sat May 01, 2004 11:13 pm Posts: 2133 Location: Grimsby - At home
|
i have this i have made,
http://rapidshare.de/files/17600419/Vil ... l.zip.html
there are 4 time slots, morning, afternoon, evening and evening extension. these can be used by the ID 1,2,3,4 respectivly.
There are bookings most days and i need to be able to bring up a box and select a month like i have in my "invoice" report. it then, depending on the month selected, needs to create a form that shows monday to sunday and a % of these days sued throught that month!
so i need to create a report that looks up every single time slot on every day and shows all 7 days and their percentage of usage.
So i get something that looks like this for january and february in a access form,(snazzy colours not needed;) )
This is needed as i need to learn how this is done for the exam, the exam consists of questions on this project and we have to answer questions on how we made it and exactly what we did!
so i need to know how i can do this please, i have tried myself but all i can do is create a form with the days all ready i dont know the code to put in to get %ages!!!!
Thanks for any help here!
_________________
|
|
|
|
|
Varp
|
Post subject: Posted: Mon Apr 10, 2006 7:22 am |
|
|
Pure sex on legs |
Joined: Thu Mar 04, 2004 4:45 pm Posts: 583 Location: Zummerzet, UK
|
so to clarify:
your program needs to know:
1. how many days there are in the current month
2. what day of the week any particular date might be (or is that data already stored in your table ?)
3. you'll then need a few queries which feed into another query (which is then the datasource for your form/subform)
- try looking at the SQL Domain Agregate Functions help in Access, in particular SELECT COUNT([idField]) WHERE WeekDay([myDateField]) = 1
- so you'll also want to look up Access Date functions (for the WeekDay() bit)
PS
I'm guessing missing Friday out from your piccy was just a typo ??
|
|
|
|
|
Scorchedbee =GCHQ=
|
Post subject: Posted: Mon Apr 10, 2006 9:43 am |
|
|
I Burn Insects |
|
Joined: Sat May 01, 2004 11:13 pm Posts: 2133 Location: Grimsby - At home
|
yer friday was a typo, i have a qurey that lets ne picj a certain month, not i just need to get this thing to sort out each day and give me a %age of each time slot Too hard this!
_________________
|
|
|
|
|
Varp
|
Post subject: Posted: Tue Apr 11, 2006 7:10 am |
|
|
Pure sex on legs |
Joined: Thu Mar 04, 2004 4:45 pm Posts: 583 Location: Zummerzet, UK
|
I don't believe you can use loops in JET SQL (Access's query language). You could write a query using recordsets in the form's code (VBA) and loops through that way, but that'll perform quite slowly.
SELECT COUNT gives the number of rows which match some criteria
so you need several SELECT COUNT queries to find out how many records meet each criteria, then an uber query to gather all those results into one set of data to present it to your form. Or you could do it in one nested query.
So that leaves you with writing several different queries each of which give you an element of your final result.
Have you covered Recordsets or SQL in your course ?
(wouldn't want to give you help finding an answer you wouldn't know from your course )
SELECT Item, Count(Item) AS Tally FROM Products
GROUP BY Item;
Will give one row for each item type with a count next to it...
that helping ?
|
|
|
|
|
Scorchedbee =GCHQ=
|
Post subject: Posted: Tue Apr 11, 2006 11:23 am |
|
|
I Burn Insects |
|
Joined: Sat May 01, 2004 11:13 pm Posts: 2133 Location: Grimsby - At home
|
wow really helpful post, ill try it, though im not 100% whats quite going one, lol.
btwno i havent covered Recordsets or SQL in my course, hardly any of the stuff im doing tbh. Thanks for the help so far, ill see if i cna do this today, though doubt it, because i need to learn what im doing for the exam. Thanks again!!!
_________________
|
|
|
|
|
Scorchedbee =GCHQ=
|
Post subject: Posted: Wed Apr 12, 2006 9:04 am |
|
|
I Burn Insects |
|
Joined: Sat May 01, 2004 11:13 pm Posts: 2133 Location: Grimsby - At home
|
well i tried it!
i have the count query done, i get either 1,2,3 or 4 for each date, now how do i work the %age in a form in access or do i need to run a query and tell it something like when 4 =100% when 3=75% etc? But how on earth would you do that!
Im thinking it must be fairly easy as its out of 4 so is there some code i need?
Thanks for the continued help!
_________________
|
|
|
|
|
Varp
|
Post subject: Posted: Wed Apr 12, 2006 11:29 am |
|
|
Pure sex on legs |
Joined: Thu Mar 04, 2004 4:45 pm Posts: 583 Location: Zummerzet, UK
|
It's always better, more efficient and ultimately easier to do as much of the number-crunching in the SQL and just let the form concentrate on the shiney stuff.
Is the maximum possible 4 ?
If it is then your query just needs to have something like
SELECT 100/(SELECT COUNT(myField) FROM myTable) as MyPercentage
If it isn't then you need to do a more complicated sum something like
(Actual Count / Maximum Possible) * 100
|
|
|
|
|
Scorchedbee =GCHQ=
|
Post subject: Posted: Wed Apr 12, 2006 4:53 pm |
|
|
I Burn Insects |
|
Joined: Sat May 01, 2004 11:13 pm Posts: 2133 Location: Grimsby - At home
|
i did this, and i get an "error -3005 no error is defined ....."
_________________
|
|
|
|
|
|