Date and time / separate - combine problem

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I have one field in the table:
startdateandtime

I have 3 textboxes on the form:
txtstartdateandtime
txtstartdate
txtstarttime

txtstartdateandtime is bound to the table field and is not visible.
txtstartdate and txtstarttime are meant to make it easier for the user than
a single field would be.

On the AfterUpdate events of both txtstartdate and txtstarttime I use the
following:

Me.txtStartdateandtime = CDate(Nz(Me.txtStartdate, 0)) +
TimeValue(Nz(Me.txtStarttime, "00:00:00"))
Me.Repaint

to put the entered values into the bound field (and then into the table).

This works. But when I put the following in the OnCurrent event of the
form:

Me.txtStarttime = Format([Startdateandtime], "hh:nn ampm")

to set the table value in the form so the user can see it I get a
type-mismatch error later when the AfterUpdate event is fired.

How can I correct this?

Robert
 
Use the "txtStarttime" textbox's Format property to set that format. No need
for VBA code at all.
 
Sorry - my first post will give you the correct format, but this is what you
need to separate out the time value from the date/time field:

Me.txtStarttime = TimeValue([Startdateandtime])
 
That worked. Thanks!
Ken Snell (MVP) said:
Sorry - my first post will give you the correct format, but this is what
you need to separate out the time value from the date/time field:

Me.txtStarttime = TimeValue([Startdateandtime])

--

Ken Snell
<MS ACCESS MVP>



Robert said:
I have one field in the table:
startdateandtime

I have 3 textboxes on the form:
txtstartdateandtime
txtstartdate
txtstarttime

txtstartdateandtime is bound to the table field and is not visible.
txtstartdate and txtstarttime are meant to make it easier for the user
than a single field would be.

On the AfterUpdate events of both txtstartdate and txtstarttime I use the
following:

Me.txtStartdateandtime = CDate(Nz(Me.txtStartdate, 0)) +
TimeValue(Nz(Me.txtStarttime, "00:00:00"))
Me.Repaint

to put the entered values into the bound field (and then into the table).

This works. But when I put the following in the OnCurrent event of the
form:

Me.txtStarttime = Format([Startdateandtime], "hh:nn ampm")

to set the table value in the form so the user can see it I get a
type-mismatch error later when the AfterUpdate event is fired.

How can I correct this?

Robert
 
Back
Top