Date/time edits

  • Thread starter Thread starter Rose B
  • Start date Start date
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?
 
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
 
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
 
Back
Top