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

How to find the second fastest time in a table

489 256MB
I am using Access 2007. I have a table that has a member number and up to eighteen different times. Table has Col. MbrNumber Time1, time2 etc.
I want to be able to eliminate the fastest of the 18 times and save the second fastest time somewhere. What would be the an easy way to do this.
Jul 26 '12 #1

✓ answered by twinnyfo

CD Tom,

Your table makes this more difficult, because it has these values in separate fields, rather than in rows, but I can understand why you might want to have it set up this way.

I would declare two public variables, one for the fastest time, another for the second fastest time.

I would declare a function that could be called from within your code which would compare the current values of those two best times, and update the global variables as necessary. You have to determine where the first two time values fall first. You just need to determine what you will do with the final value.

I won't give code for getting your table values into this loop, as you will probably either use a recordset, or draw directly from a form--your choice. Depends on how you are using this second best value.

This should work, and rather quickly, since it is just cycling through 18 values.

Let me know how it works.....

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public dtmNumberOne As Date
  5. Public dtmNumberTwo As Date
  6.  
  7. Private Sub FindTopTwo()
  8.     dtmNumberOne = Time1
  9.     If Time2 < dtmNumberOne Then
  10.         dtmNumberTwo = dtmNumberOne
  11.         dtmNumberOne = Time2
  12.     Else
  13.         If Time2 < dtmNumberTwo Then dtmNumberTwo = Time2
  14.     End If
  15.     EvaluateTime Time3
  16.     EvaluateTime Time4
  17.     EvaluateTime Time5
  18.     'Etc.....
  19.     Debug.Print dtmNumberTwo
  20. End Sub
  21.  
  22. Private Function EvaluateTime(dtmTime As Date)
  23.      If dtmTime < dtmNumberOne Then
  24.         dtmNumberTwo = dtmNumberOne
  25.         dtmNumberOne = dtmTime
  26.     Else
  27.         If dtmTime < dtmNumberTwo Then dtmNumberTwo = dtmTime
  28.     End If
  29. End Function
  30.  

4 1562
twinnyfo
3,653 Expert Mod 2GB
CD Tom,

Your table makes this more difficult, because it has these values in separate fields, rather than in rows, but I can understand why you might want to have it set up this way.

I would declare two public variables, one for the fastest time, another for the second fastest time.

I would declare a function that could be called from within your code which would compare the current values of those two best times, and update the global variables as necessary. You have to determine where the first two time values fall first. You just need to determine what you will do with the final value.

I won't give code for getting your table values into this loop, as you will probably either use a recordset, or draw directly from a form--your choice. Depends on how you are using this second best value.

This should work, and rather quickly, since it is just cycling through 18 values.

Let me know how it works.....

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public dtmNumberOne As Date
  5. Public dtmNumberTwo As Date
  6.  
  7. Private Sub FindTopTwo()
  8.     dtmNumberOne = Time1
  9.     If Time2 < dtmNumberOne Then
  10.         dtmNumberTwo = dtmNumberOne
  11.         dtmNumberOne = Time2
  12.     Else
  13.         If Time2 < dtmNumberTwo Then dtmNumberTwo = Time2
  14.     End If
  15.     EvaluateTime Time3
  16.     EvaluateTime Time4
  17.     EvaluateTime Time5
  18.     'Etc.....
  19.     Debug.Print dtmNumberTwo
  20. End Sub
  21.  
  22. Private Function EvaluateTime(dtmTime As Date)
  23.      If dtmTime < dtmNumberOne Then
  24.         dtmNumberTwo = dtmNumberOne
  25.         dtmNumberOne = dtmTime
  26.     Else
  27.         If dtmTime < dtmNumberTwo Then dtmNumberTwo = dtmTime
  28.     End If
  29. End Function
  30.  
Jul 26 '12 #2
CD Tom
489 256MB
thanks for the reply I think that will work.
Jul 27 '12 #3
twinnyfo
3,653 Expert Mod 2GB
My pleasure! Let me know if there's anything else I can help with!
Jul 30 '12 #4
zmbd
5,501 Expert Mod 4TB
@CD Tom
CD Tom:
Taking a bit of time to normalize your database will really help out with this type of problem.
I found the following to be a good review for myself and an excelent explanation of Database Normalzation concepts. Once your database is normalized, you find this information using a simple query without the need for VBA.

As for the table format you have going, a cross-tab query would return the data in the format you have laid out.

-z
On Vacation with a Strange PC and a Funky Keyboard... where's that spell check... Rabbit... where'd that come from? Late for what... well it is 2am
Jul 31 '12 #5

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

Similar topics

2
by: New Guy | last post by:
Hello, First, I want to apologize for posting this message to multiple groups. (1) I have a hard time finding any info and (2) this is not a school assignment. I am trying to create in my...
10
by: Sean Berry | last post by:
I need to find the second to last occurence of a "." in a string. Basically I am taking a URL like http://this.is.mydomin.com/path/to/file.txt and want to extract /path/to/file.txt I...
4
by: Killer42 | last post by:
Hi all. Sorry, this is probably a really simple one but I'm having some difficulty with it, and don't have much time to devote to it right now. I need to find all the records which have...
4
by: tathagata | last post by:
I want second highest value in a table without using subquery. please send this answer .It will be very helpfull.
3
by: santybanty20 | last post by:
i got a project on time table creation of a department so any one having the code for the project please send it to me... the i/p:--- u have to enter no of classes,no of teacher,no of class,and...
0
by: janbazamin | last post by:
Hi Dear. I am making time table application in ASP.NET i am facing some problem i am adding Start time, End Time In Database. on some date. if i again select same date and stat time and end time. i...
0
by: janbazamin | last post by:
I am making time table application in ASP.NET i am facing some problem i am adding Start time, End Time In Database. on some date. if i again select same date and stat time and end time. i am...
5
by: Ishmael | last post by:
Hi Is Been a 3 Yrs Now (I Still trying to do this) Please help me to do this with Visual Basic 6.0 using Msflexgrid Let say you are the Principal . You have 10 educators and 5 class (Grades)...
9
alisyah
by: alisyah | last post by:
is it possible to insert the time table in database?
1
by: Zabivb | last post by:
Hai guys!!! I'm doing a project of college management, now my task is to generate time table automatically dependending up on the subject details ... Any help will be great. Thanks
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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...

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.