Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting listbox hours and listbox minutes to date/time format

Posted on 2006-11-22
15
Medium Priority
?
268 Views
Last Modified: 2008-02-01
I'm designing a form on which there will be elapsed time for an activity.  I want to have two unbound list box controls, one for hours and another for minutes.  In this particular application minutes will be reported only in 15 minute intervals.  The hour list box will have 1, 2, 3, 4.  The minute list box will have 00, 15, 30, 45.  I'd like to have a third not visible control that is bound to a field in the table with regular date/time format.  The conversion from the list boxes to the bound control will take place in the list boxes AfterUpdate events.  What formula do I use for the conversion?
0
Comment
Question by:WFBweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +3
15 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 400 total points
ID: 17996225
Does this do the trick?

txtInvisibleControl = CDate (ListboxHrs & ":" & ListBoxMins)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17996246
there is also timeserial that u can use

timeserial(lstHours, lstMinutes, 0)

returns the time
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17996259
"Miriam, why is that a administrative comment then"
he asks cheekily :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 61

Expert Comment

by:mbizup
ID: 17996312
Rocki: I don't know what you're talking about. ;-)
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17996361
I think you need to determine which order the controls need to be , or will be filled out in so you can update the invisible textbox value in the afterupdate event of the lstHours and/ or lstMinutes. Maybe do it for both so you can be sure to catch it no matter which order they enter the data in.

Private Sub lstHours_AfterUpdate()
Dim dtmElapsed As Date

    'set date variable to 0 (12/31/1899 12:00 AM)
    dtmElapsed = 0
    DateAdd("h", Me.lstHours.Value, dtmElapsed)  
    DateAdd("n", Me.lstMinute.Value, dtmElapsed)  
    Me.txtEventEnd.Value = dtmEnd
End Sub

Private Sub lstMinutes_AfterUpdate()
Dim dtmElapsed As Date

    'set date variable to 0 (12/31/1899 12:00 AM)
    dtmElapsed = 0
    DateAdd("h", Me.lstHours.Value, dtmElapsed)  
    DateAdd("n", Me.lstMinute.Value, dtmElapsed)  
    Me.txtEventEnd.Value = dtmEnd
End Sub
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17996421
I swear, it showed up as admin comment.
I must be seeing things, surely u would never abuse your power :-D
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17996505
(Off Topic)

Rock:  If Miriam's only badger-like problem here is inadvertently posting comments as Admin Comments, then she's doing pretty well. :)
0
 

Author Comment

by:WFBweb
ID: 17996577
mbizup: Works fine...thanks! I changed the hours list box to 0,1,2,3.  I made the default 0 and the default of the minutes list box 00.  That way no matter what order they enter data in or if they skip one of the fileds becaue the default is ok, it works.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17996607
Glad to help :-)
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17996631
For the sake of completeness, tbxInvisible control source:

=CDate(CStr(Me!lbxHours & ":" & Me!lbxMinutes) or

=TimeSerial(Me!lbxHours,Me!lbxMinutes,0)
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17996664
WFBweb,  I'm not looking for anything, but didn't you have to prefix the listbox references with Me! or Me. ?
0
 

Author Comment

by:WFBweb
ID: 17996771
I don't know if I had to, but I did it 'automatically' the first time I tried it (and with brackets around the control name).
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17996782
Ray,
The Me. prefix is needed for intellisense, and is better programming style, but is not needed to get the selected value.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17997070
So I found out.  I still think it behooves the 'Experts' to consistently display the 'better programming style'.  I've been playing with Access for over 15 years now and just the other day I 'discovered' you can create a form with no controls, bind it to a table, and determine the value of every field in the table from code - as well as manipulate the table.  While that may have been obvious to you, you could say it took my breath away.  All the while I had thought you needed controls.  And another one (strongly held belief) bites the dust - oh well!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17997334
Howdo Jim
just teasing of course :)
Anyways what u doing here, I thought u were taking a well deserved break
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question