Convert to VBA code?

D

Darrell Childress

I originally had a button that, when clicked, would run a macro. I now
need to write the VBA code for that instead, and need help. Here's what
I am trying to accomplish:

My form contains a field called TimeStop which contains Date/Time in the
format of 3/22/10 10:05:06 AM
I need to populate a field called DateStop and the value of that field
will depend on the TIME portion of TimeStop. If TimeStop is between
12:00:00 AM (midnight) and 5:00:00 AM, then I need DateStop to be the
current date - 1. Otherwise, I need it to be the current date.

Here's my stab at it, but I don't know the correct syntax to use

If TimeValue(Me.TimeStop) is between #12:00:00 AM# and #5:00:00 AM" Then
Me.DateStop = Date()-1
Else
Me.DateStop = Date()
End If

Thanks for any help,
Darrell
 
T

Tom van Stiphout

On Mon, 22 Mar 2010 10:20:22 -0400, Darrell Childress

Pretty close.

If TimeValue(Me.TimeStop) < #5:00:00 AM# Then
Me.DateStop = DateAdd("d", -1, Date())
Else
Me.DateStop = Date()
End If

-Tom.
Microsoft Access MVP
 
D

Darrell Childress

works great, thanks Tom. I thought I was close.

On Mon, 22 Mar 2010 10:20:22 -0400, Darrell Childress

Pretty close.

If TimeValue(Me.TimeStop)< #5:00:00 AM# Then
Me.DateStop = DateAdd("d", -1, Date())
Else
Me.DateStop = Date()
End If

-Tom.
Microsoft Access MVP
 
D

Darrell Childress

Thanks, Daryl. I had just tried Tom's suggestion, which worked. I need
to do this to another macro, and I will try this...I never knew that
existed.
 

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