Date/time question

  • Thread starter Thread starter Philo Hamel via AccessMonster.com
  • Start date Start date
P

Philo Hamel via AccessMonster.com

In one of my tables I have a date/time field. On a form I want to have two
seperate textfields: one for entering the date and one for entering the time.
After entering the date, I want to automaticly add #05:00:00 PM#. After
entering the date the user can chose to change the time (the time textfield
is now displaying 17:00) if they need to. How do I get this to work?

TIA
Philo
 
Add 2 unbound text boxes to the form. Name the first (say) txtDate, and set
its Format property to Short Date. Name the second one txtTime, and set its
Format to Short Time. (The formats help Access understand the intended data
type for unbound controls.)

In the current event of the form, populate the text boxes.
This example assumes the date/time field is named DT:
Private Sub Form_Current()
If IsNull(Me.DT) Then
Me.txtDate = Null
me.txtTime = Null
Else
Me.txtDate = DateValue(Me.DT)
Me.txtTime = TimeValue(Me.DT)
End If
End Sub

In the AfterUpdate event of the text boxes, write the value to the field:
Private Sub txtDate_AfterUpdate
If IsNull(Me.txtDate) And IsNull(Me.txtTime) Then
Me.DT = Null
Else
Me.DT = Nz(Me.txtDate, #00:00:00#) + Nz(Me.txtTime, #00:00:00#)
End If
End Sub

Private Sub txtTime_AfterUpdate
Call txtDate_AfterUpdate
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
Back
Top