Date and time / separate - combine problem

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
 
K

Ken Snell \(MVP\)

Use the "txtStarttime" textbox's Format property to set that format. No need
for VBA code at all.
 
K

Ken Snell \(MVP\)

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])
 
R

Robert

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
 

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