Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 26th, 2003, 07:25 AM
Earhart Earhart is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 Earhart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Adding Hours

I've been trying to subtract times i.e. 15.40 to 16.10 and cummulatively add these hours in order to track flight hours.

I can complete this if I convert the times to decimal times i.e. 1530hrs become 15.50.

I would like to be able to get Access to subtract and track hours with out this decimalisation. Is this possible?

Help Please....

Reply With Quote
  #2  
Old November 26th, 2003, 10:19 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
I don't know if it is possible with a value such as 15.45 which would reference as 15.75 as decimal. Access stores dates as whole numbers and time as a decimal of that number.

I have only every just used the time the way access stored it and done calulations to it in that state and then converted it to something that makes sense to the users.

Good Luck
S-

Reply With Quote
  #3  
Old November 26th, 2003, 01:39 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Hi

1. To Add or Subst. time values, they should be first converted to minutes. The following function does that:

'*********************************
Private Function TimeToMinutes(strTime As String, Optional Separator As String = ":") As Long
TimeToMinutes = Val(Left(strTime, InStr(1, strTime, Separator) - 1)) * 60 + Val(Mid(strTime, InStr(1, strTime, Separator) + 1))
End Function
'*********************************
Note: if you don't use ":" as separator character between hour and minute digits but you use a different one, then you must include the separator character in the function call, as the second parameter.

2. After converting the time values to minutes, they can be normally added or substracted. After calculating the minutes, the return value should be converted back to hh:mm format. The following code does that:
'*********************************
Private Function MinutesToTime(lngMinutes As Long, Optional Separator As String = ":") As String
Dim lngHourPart As Long
Dim lngMinutePart As Long
Dim strHourPart As String
Dim strMinutePart As String
lngMinutePart = lngMinutes Mod 60
lngHourPart = (lngMinutes - lngMinutePart) / 60
If lngHourPart < 10 Then
strHourPart = "0" & Trim(Str(lngHourPart))
Else
strHourPart = Trim(Str(lngHourPart))
End If
If lngMinutePart < 10 Then
strMinutePart = "0" & Trim(Str(lngMinutePart))
Else
strMinutePart = Trim(Str(lngMinutePart))
End If
MinutesToTime = strHourPart & Separator & strMinutePart
End Function
'*********************************
Note: if you do not specify a separator character in the function call then a ":" will be the separator character.

3. And here we come. The function that makes the calculation:
Public Function CalculateTime(strTime1 As String, strTime2 As String, Optional Operation As String = "Add") As String
Dim lngTurnValue As Long
Dim SubValue As Long
If Not (Operation = "Add" Or Operation = "Substract") Then
Operation = "Add"
End If
If Operation = "Add" Then
SubValue = TimeToMinutes(strTime1) + TimeToMinutes(strTime2)
Else
SubValue = TimeToMinutes(strTime1) - TimeToMinutes(strTime2)
End If
If SubValue > 1440 Then
SubValue = SubValue - 1440
Else
If SubValue < 0 Then
SubValue = SubValue + 1440
End If
End If
CalculateTime = MinutesToTime(SubValue)
End Function
This is the function that you call from your query or form.
Note: this function IGNORES the date! It does NOT add 1 to the date if the result of the operation is beyond 1440 minutes (which is 24 hours), and does NOT substract 1 from the date if the result of the operation runs under 0.

Bonus:
Here is a sub to test the function group (this should return "23:30"):
'*********************************
Private Sub test()
MsgBox CalculateTime("15:30", "16:00", "Substract")
End Sub
'*********************************
I hope this helps.

Regs,

TBÁrpi

Last edited by TBÁrpi : December 15th, 2003 at 05:27 PM.

Reply With Quote
  #4  
Old November 26th, 2003, 04:51 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Sorry, line 12 of CalculateTime function is:

If SubValue > 1440 Then

instead of:

If SubValue > 480 Then

BRegs,

TBÁrpi

Reply With Quote
  #5  
Old November 26th, 2003, 10:36 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
TBÁrpi

Very nice. I will have to remember this.

S-

Reply With Quote
  #6  
Old November 27th, 2003, 09:14 AM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Ruth,

Of course you can send, if so, then use LostPilgrim@email.com.

BUT, to be honest, I give you trawl rather than fish... and don't worry about thinking you stupid. No one on Earth is born with programming knowledge.

The code I sent you should be pasted into a Module. Go to Modules tab, click New, and copy-paste the codes between the '********************* lines of my message. Then click Debug->Compile menu to

ensure that there is no compile error in the code. Then save the module. Give it any name.

To run the sub Test, place the cursor anywhere WITHIN the sub Test, and press F5 on the keyboard. A message box should appear showing 23:30. If so, then it's working OK. If you wish to see how it

works step-by-step, place the cursor anywhere WITHIN the sub Test, and press F8 on the keyboard. As you press F8 again and again, the execution goes a step, and highlights the line that is going to

be next executed. During step-by-step execution, if you move (and not click) the mouse above a variable, a tool tip will appear and show the current value of that variable.

Now, let's say you have a table called 'tblTime' with two fields:
Depatrure (type: text, length: 5)
FlightDuration (type: text, length: 5)

Create the table, and add some records to it.
Both field should be filled in HH:MM format, eg. 12:40, 05:15 etc.

Now, go to queries, click New.

Close the Show Table dialog box without adding any tables, and switch to SQL view. Paste the following SQL command there:

select Departure, FlightDuration, CalculateTime([Departure],[FlightDuration]) as Arrive from tblTime

Now switch to Design view, and you can see how the query is built visually. If you execute the query, it should show you the Arrive times.

Of course, if you already have a table to run the query on, then you can use it, but in this case the SQL command above probably won't work, so you need to edit/design your own query that works with your table.

I hope this helps. Anyway, if you still experiencing problems, send me the file.

BRegs,

TBÁrpi

Reply With Quote
  #7  
Old November 29th, 2003, 12:51 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Here's the sample file.

TBÁrpi
Attached Files
File Type: zip time.zip (23.6 KB, 297 views)

Reply With Quote
  #8  
Old November 30th, 2003, 11:48 AM
Earhart Earhart is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 Earhart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My God, you're a genius.

Would it be possible to total all the hours? I couldn't manage to do it the normal way, and I didn't want to screw with your coding!!
If the aircraft already has hours up on it, could that figure be added to the total?

Note how I have already managed to screw with your work!! (sorry could not upload)

Reply With Quote
  #9  
Old December 1st, 2003, 07:13 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Ruth,

[I am sharing this essay, because I think it can help other beginners.]

Now, as it's 01:25 in the morning, I'm going to just describe my idea.

You wrote earlier that you can use Excel for several calculations for this issue. Now, I think you shouldn't use both Excel and Acces because then you run two parallel application for a single task.

I think you first should choose between Excel and Access, but, of course, I do recommend using Access. I am not biassed against Excel. I know very well that tehre are many things that easier to carry out via Excel. But having looked at your problem and read your earlier emails I realized the mission of your application, and I think the solution can be more efficient in Access than in Excel. Access is able to run all the calculations for you. Excel has some database-like functions like HLOOKUP, FLOOKUP etc., but has no capability of relationships between tables, referential integrity, indexing and so on.

I don't really know the current completeness of your database but if I was charged with developing this application, I would start with something like the following:

- Create a table for the pilots. Data stored here would be Name, rank and "hours up" for the pilot, as a legacy data, etc. Table name would be tblPilot.
- Create a table for aicraft models. I would store here such data as type, model, manufacturer, etc. which related to a model and not to a single aircraft. I would call this table tblModel.
- Create a table with aicraft data. I would store here such data as model, serial number, date of manufacture, date of purchase, date of installation, nickname etc. I would store here those data which can be only ONE value for each aircraft, and rarely or never change. I would store here the "hours up" for each aircraft, as a legacy data. I would make sure that each aircraft has a unique identification number. The best is an AutoNumber field. I know serial number is identical, but seeking and sorting records are much faster if the ID is issued by Access when a new record is added. An AutoNumber means nothing for the user, so it can be hidden from them. Table name would be tblAircraft.
- Create a table with all the inspection/maintenance activities that should ever be carried out on a single aircraft. I would store here for example the description of the maintenance (eg. "oil charge", or "checking fuel pipe" or whatever, I don't really know what they can be for an aircraft). I also would create an AutoNumber field for record identification. Table name: tblMaintenance.
- Create a table for all the parts that should ever be changed in a single aircraft. I would store in this table such as Part Number, Description, Manufacturer, etc. I would store here the windscreen, for example. And again, an AutoNumber for record identification. Table name: tblPart
- Create a table to set up that how often a particular Model should be Maintenanced. This would have a field for defining the Model, a field for defining the Maintenance, a field for defining the time period the Maintenance should be done, and a field for the number of cycles the Maintenance should be done. This table would create a many-to-many relationship between tblModel and tblMaintenance tables. This table would exactly tell you which Model needs which Maintenance and when.
- Create a table to set up that how often a particular Part should be replaced in a Model. This would have a field for defining the Model, a field for defining the Part, a field for defining the time period the Part should be replaced, and a field for the number of cycles the Part should be replaced. This table would create a many-to-many relationship between tblModel and tblPart tables and would exactly tell you which Model needs which Part to be replaced and when.
- Create a table for logging those activities when an aircraft is with running engines for any reason. The reason can be a flight excercise, or anything that requires running engines. I would store here the Off Blocks, On Blocks, Departures, Arrives, pilot name, etc., all data that related to the activity. I would call this table tblLog.
- As a bonus, I would create a table for fuel fills.

With these tables set up, and maintaining the data in them, and accurately updating the log, you can retrieve any Maintenance or Part replacement needed for any single aircraft. And of course, you could retrieve more much statistic data such as "hours up" for a pilot, etc. There are many-many data mining possibilities e.g. consumption analysis, which can help you to keep fuel costs under control.

I know, building a database application is a bit more than just creating tables. There are many queries, forms and VB code required to get the application work, and deliver the solution.

Note: having a good database is having the power of control.

I hope this makes sense.

Good luck, and if you get stuck, let me know.

Árpi
__________________
BRegs,
TBÁrpi
"I can only show you the door. You're the one who has to walk through it."

Last edited by TBÁrpi : December 1st, 2003 at 07:39 PM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Adding Hours


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT