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

Query - selecting smallest records up to a certain (total) size

4
Hi all, my first post here, i'm a bit of a newbie when it comes to access programming.

I need to design a query that will return a number of dvd titles with a total running time of a set size (7hrs/420mins) - and it must cram in as many titles as it can. I can get access to create a running total of all the dvd's lengths, but cant get it to stop at the 420min mark.
So far i have it merely listing the data is ascending order by length, and giving me a running total in another column, using a simple select query.

Any suggestions or help would be appreciated. :)

streff.
Aug 10 '06 #1
7 2469
Do you have a field in your table that has the exact run time of each movie? If you do then in your qry put Runtime="420" or Runtime="7hrs" depending on how your field is formatted or weather you put the minutes or hours in the field data.
Aug 10 '06 #2
comteck
179 100+
What code are you using?

comteck
Aug 10 '06 #3
streff
4
Hi guys, thanks for the replies.

I'm trying to do the query using the access design view, and entering expressions into the "criteria" field, although i get the feeling that this method does not have the ability to do what i need it to.

The table has a field for the runtime of the film in minutes - "length".

Putting just length="420" in the query results in 0 listings, as none of the films are 420 minutes long.

I think what i need the query to do is keep a running total of the overall length as it selects records, and stop when that overall length exceeds 420mins; but also add the films to the total overall time in the order of smallest first, so there is as little of the 420 mins left over as possible.
Aug 10 '06 #4
comteck
179 100+
I'm not sure how to do it with a query. But it can be done using code. I'm not sure if you want to do it on a form, or if you just want to run a query and have the total appear. Not 100% sure what your application is.

comteck
Aug 10 '06 #5
streff
4
Ok, how would you do it in a form with code? I've realised its a bit complex for a query.

I have a basic grasp of programming, just not in any access or database specific areas. Heres a loose algorythm of what i think i need to do -

---------------------------------
look at the "length" column,
start a loop,
calculate the total running time of the column,
if that is over "420", drop the largest sized entry from the list
end loop
display results, preferably so i can put the results in a report, so i guess it would be a table.
---------------------------------


Basically, i need to pick out the best combination of films to fill a 7 hour (420 mins) period, from a list of dvd's and thier respective lengths, in order to watch as many titles as possible. its a bit of an abstract reason, but its a challenge i've been set, and ive been trying to figure it out all week.. lol
Aug 10 '06 #6
streff
4
Ok, got me a big book on VBA in access... a little old, called Access 97 Power Programming, but the info still seems relevent, and i can double check it all on the 'net. Also got Using access 97 to look up as well.. using acess 2003 at home, access 200 at work.
i think the way i'll try it is a form, with an output to a list box, displaying the name and individual runtimes of the movies and an unbound text box displaying the total runtime of the movies, but i'm unsure of where to put the code to actually filter the results - i will try putting in a filter button with the code on the OnClick function first, but i need to read more into VBA to actually do the process. I understand the loop functions and if statements i think i will need, its just the actual interfacing with the database part i dont know yet.

I'll update this as i go, just in case someone is interested :D
Aug 11 '06 #7
PEB
1,418 Expert 1GB
Hi everyone! You can try the follow:
1. You have to create a module in your database
2. Place the follow inside:

Option Explicit
Global last_criteria
Global last_used

Function Set_last(Values, criterias)
last_criteria = criterias
last_used = Values
Set_last = last_used
End Function
Function show_last(criterias)
show_last = last_used
End Function

3. USE append query to insert the results in a new table! Other way your results won't be true!

4. To do a running Sum you have to do the follow:
INSERT INTO New_table(f1,f2,f3)
SELECT film, mylength, Set_last(val(show_last(mylength))+mylength , film)
FROM my_table;

Have a nice luck!
Aug 30 '06 #8

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

Similar topics

0
by: unixman | last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to posting in the newsgroups for help. :) Simple problem, in theory. Given table "map": CREATE TABLE map ( entry_id...
4
by: sah | last post by:
I need some help with the following query: DECLARE @SRV VARCHAR(20), @date smalldatetime SET @SRV = (select @@servername) SET @date = '20040901' select Srv_Name = @SRV, DB_Name = 'DB_NAME',...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
2
by: phaddock4 | last post by:
Please help. GOAL: I hope to calculate a total amount in a TotalQuery (or field in the SubQuery?), based upon three field amounts in a SubQuery. STATUS: When I create an expression in the...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
1
by: Regnab | last post by:
I often want to query the database with certain parameters in my query which I do not want included in the query result. The problem is when I want to group on 1, sum the 2nd (and group by) and...
2
by: shanfitzpatrick | last post by:
Ach, I'm in a bind...i can't get one of my queries to work properly. And i'm certain it's because I don't know how to write the expression correctly... I am creating a database that enters items...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
5
by: jonceramic | last post by:
Hi All, I started developing in Access, and people took notice and so we're starting to migrate into our corporate's bigger Oracle system. I'll still be using my developed Access front ends,...
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
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.