Wrox Programmer Forums
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 15th, 2005, 04:28 PM
Authorized User
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stock Time in field

Hello all,
Here is a little question.
I'd like to store a time in a field like this "2mn. 13sec." but I like the user just to type "2:13". Got an idea?
I'd like it to be also entered in milliseconds "2:13:154".

I tried to solve this with input masks, but without any sufficient answers.

Thank you
Old February 15th, 2005, 11:24 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

Actually what you're attempting to store here, and what your users are entering, are simple string values, not time values as time values are understood by Access (8-byte floating point numbers).

You would need to write a little string parsing routine to locate the semi-colon in your string (e.g., Instr (1, "2:13", ":")), then parse off the characters strings to the right and left of the semi-colon, and append "mn." and "sec." respectively to the two sub-strings.

If I get some time I'll give it a whirl.


Old February 15th, 2005, 11:39 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

Also, if "2mn. 13sec." represents some sort of elasped time value, a better design might be to store an actual staring time value and ending time value in two Date/Time datatype fields (which would give you actual time values to work with), then calculate the elapsed time value in a query and format the time values there (though the custom format would still require treating the time value as a string in code somewhere so you could append the custom "mn." and "sec."
 suffix strings).


Old February 16th, 2005, 09:04 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

Try parsing this with Split() instead of colon, like this:

If IsNull(Me.tbxYourTextBox) Then
   stTime = "00:00:000"
   Else: stTime = Me.tbxYourTextBox
End If

TimeArray = Split(stTime, ":")
   stMin = TimeArray(0)
   stSec = TimeArray(1)
   stMls = TimeArray(2)
stStoredValue = stMin & "mn. " & stSec & "sec. " & stMls & "mls."

   You may need to add error handling for missed milliseconds, etc.



Similar Threads
Thread Thread Starter Forum Replies Last Post
stock management- closing stock and opening stock bright_mulenga Access 1 July 16th, 2007 07:11 AM
Null Value for Date/Time Field ksegars4 Crystal Reports 2 November 17th, 2004 11:58 AM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM
Format Date to time field KennethMungwira VB.NET 3 November 17th, 2003 11:48 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.