Date/time edits

R

Rose B

I have a date/time field in a table that I would ideally like the user to be
able to edit separately on a form - i.e. edit the date in a Date format
control and the time in a Time format control. The form display is fine but
as soon as either field is clicked the full value (date and time) is
displayed - which is very confusing for the user. Is there any way to crack
this other than actually splitting the underlying field?
 
D

Douglas J. Steele

Unless you're talking about a continuous (or datasheet) form, you could put
a couple of unbound text boxes on the form (one for the date and one for the
time), with the bound date/time textbox on the form but not visible.

In the form's Current event, assign values to the two unbound controls:

Private Sub Form_Current()

Me!MyDateOnlyTextbox = DateValue(Me!MyDateTimeTextbox)
Me!MyTimeOnlyTextbox = TimeValue(Me!MyDateTimeTextbox)

End Sub

In the AfterUpdate event of the two unbound text boxes, put code to reassign
the value to the bound field:

Private Sub MyDateOnlyTextbox_AfterUpdate()

Me!MyDateTimeTextbox = Me!MyDateOnlyTextbox + Me!MyTimeOnlyTextbox

End Sub

Private Sub MyTimeOnlyTextbox_AfterUpdate()

Me!MyDateTimeTextbox = Me!MyDateOnlyTextbox + Me!MyTimeOnlyTextbox

End Sub
 
R

Rose B

Thanks!!!!

Douglas J. Steele said:
Unless you're talking about a continuous (or datasheet) form, you could put
a couple of unbound text boxes on the form (one for the date and one for the
time), with the bound date/time textbox on the form but not visible.

In the form's Current event, assign values to the two unbound controls:

Private Sub Form_Current()

Me!MyDateOnlyTextbox = DateValue(Me!MyDateTimeTextbox)
Me!MyTimeOnlyTextbox = TimeValue(Me!MyDateTimeTextbox)

End Sub

In the AfterUpdate event of the two unbound text boxes, put code to reassign
the value to the bound field:

Private Sub MyDateOnlyTextbox_AfterUpdate()

Me!MyDateTimeTextbox = Me!MyDateOnlyTextbox + Me!MyTimeOnlyTextbox

End Sub

Private Sub MyTimeOnlyTextbox_AfterUpdate()

Me!MyDateTimeTextbox = Me!MyDateOnlyTextbox + Me!MyTimeOnlyTextbox

End Sub
 

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

Similar Threads

time edit 1
date time picker 4
Input Mask for General Date/Time 1
Changing a Medium Time 5
Subforms - Date/Time 2
Time field continues to show date 3
Editing formatted date in textbox 3
Cannot enter time in form 4

Top