New Time InputBox Question

G

Guest

How do I format the date specifically in a input box output? I have this:

Dim BegTime As Date


BegTime = InputBox("Select start time of Tirtl Count. Use Time (_:__
AM) structure!", "Select Beginning Time")
Me.LstBegDate = BegTime
Me.LstEndTime = DateAdd("h", 1, Me.LstOrgBTime)

But it does not show up in my lstbox at all, so how do I format the date to
"hh:nn AM/PM" so it will show up in the lstbox? The lstbox already has an
imput mask of "hh:nn AM/PM". Thanks!
 
A

Allen Browne

Internally, Access uses a floating point value to store a date. The whole
number represents the date, and the fractional part the time of day. That
means a date in a date/time variable has no inherent formatting. The
formatting is applied at display time.

An input box returns a string value, and has no Format. Despite the fact
that you asked for a date, the user can type in:
get lost
and the InputBox will accept it.

So, you might like to test whether the value can be understood as a date,
and keep looping until the enter a valid value (or cancel if they make no
attempt at all.) Then use CDate() to force the value to a Date/Time value:

Dim strBegTime As String
Dim bCancel As Boolean

Do
strBegTime = Trim(InputBox("Select start time"))
If strBegTime = vbNullString Then
bCancel = True
Exit Do
End If
Loop Until IsDate(strBegTime)

If Not bCancel Then
Me.LstBegDate = CDate(strBegTime)
'etc.
End If

Since the list box itself is bound to a Date/Time value, you can set its
Format property to Short Time. (Alternatively, if you are assigning values
to the non-bound column of a multi-column list box, use the Format()
function to format the value in its RowSource.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top