Solved

Between Times Access VBA

Posted on 2014-03-13
5
550 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

747 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