user194076
user194076

Reputation: 9017

Time picker access 2007

I want my users to select only time for datetime filed in access 2007. I found that there's a built-in date control, but cannot find time control. Does anyone know if there's a way to have a time picker control?

Upvotes: 0

Views: 3447

Answers (1)

HansUp
HansUp

Reputation: 97101

For entering time values, a specialized control doesn't offer the user much more, if any, convenience than directly entering time values into a text box bound to a Date/Time field, IMO.

For 1:30 PM, she can just enter 1:30p, and it will be accepted appropriately. She could also enter that time as 13:30 if she prefers.

If your concern is preventing the user from entering a (non-zero) date value along with the time, you can discard the date portion in the text box's after update event. Users tend to catch on real fast when the date portions of values they enter are discarded.

Private Sub txtTimeOnly_AfterUpdate()
    Me.txtTimeOnly = TimeValue(Me.txtTimeOnly)
End Sub

Actually that will convert the date portion to VBA's day zero, #1899/12/30#. But that's the best you can hope for to store a "time only" value because Date\Time values always include a date in both VBA and the database field type.

If you want more assurance the field will store time values (with #1899/12/30# as the date), you can set a validation rule on the table:

IsNull([time_only_field]) Or DateValue([time_only_field])=CDate("1899/12/30")

If you still feel you need a time picker control for this, search the web to see if anyone has created one. I would avoid an ActiveX control because they wind up creating version problems.

Or I suppose you could create your own custom time picker with combo boxes: one for hours; one for minutes; and, if needed, one for seconds. In the combo after update events, build your time value from those pieces and store them in a control bound to the time_only_field. That control needn't be editable by the user, but making it visible would allow them to see the completed value.

Upvotes: 2

Related Questions