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
 
D

Dale_Fye via AccessMonster.com

You might consider making these two fields "unbound" and filling them in the
forms current event. This assumes that you have a bound textbox (txtDateTime)
which I would recommend hiding, and two unbound textboxes (txtDate, txtTime).
In the forms Current event, you would do something like:

Private Sub Form_Current

if not isnull(me.txtDateTime) then
me.txtDate = DateValue(me.txtDateTime)
me.txtTime = TimeValue(me.txtDateTime)

end if
End Sub

Then, in the AfterUpdate event of txtDate and txtTime, you would concatenate
those values and update txtDateTime. Something like:

Private Sub txtDate_AfterUpdate

if len(me.txtDate & "") = 0 and len(me.txtTime & "") = 0 then
me.txtDateTime = NULL
elseif len(me.txtDate & "") > 0 and len(me.txtTime & "") = 0 then
me.txtDateTime = cdate(me.txtDate)
elseif len(me.txtDate & "") = 0 and len(me.txtTime & "") > 0 then
'if the time is entered, but date is not, then don't set the DateTime
field
me.txtDateTime = NULL
else
me.txtDateTime = cdate(me.txtDate) + cdate(me.txtTime)
endif

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

Top