Solved

Between Times Access VBA

Posted on 2014-03-13
5
572 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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