Solved

Between Times Access VBA

Posted on 2014-03-13
5
554 Views
Last Modified: 2014-03-13
I have a Time field that records the time of day a record was added (Not Date).

I want an event to occur if when this time is achieved (there are other filters which control the event).

In simple terms I want the event to occur if between Now() -1 30 minutes and Now() + 30 minutes, but not referring to a Date.
0
Comment
Question by:SparkyP
  • 2
  • 2
5 Comments
 
LVL 84
ID: 39926004
So you need something that counts up to your interval?

If you're doing this on a Form, you could use the form's Timer event. To do that:

1. Add a Date variable to the General Declarations section of the form to hold the value of "Now"

2. When you want to start the count up:

dtYourVariable = Now

And set the Timer's interval to something like 2000 (which means it'll fire every 2 seconds). This essentiall starts the timer.

3. In the form's Timer event:

'/ "n" is the DateAdd value for Minutes
If DateAdd("n", 30, dtYourVariable) > Now Then
  '/ do what you want here
  Me.TimerInterval = 0 '<< stops the timer
End If
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39926122
you can use the Time() function instead of Now() since you don't want the date part.
0
 

Author Comment

by:SparkyP
ID: 39926168
Scott

I'm sure your solution would work, but I was hoping for a simpler solution, like between Time() - 30 and Time() +30, with the 30's being in seconds.

From your reply this isn't possible?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39926297
I don't think I understood your issue at first ...

So you have a field in a table, and you've recorded the Time a record was inserted/updated (or whatever).

If so, then you could do something like this in the Form's Timer event:

If Me.YourTimeField > Time(Now) and Me.YourTimeField < DateAdd("n", 30, Time(Now)) Then
  '/ do something here
End If
0
 

Author Closing Comment

by:SparkyP
ID: 39926309
Thanks Scott
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now