Solved

Between Times Access VBA

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

690 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