Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-31-2012, 09:54 AM   #1
umair434
Newly Registered User
 
Join Date: Jul 2011
Location: CA
Posts: 186
Thanks: 24
Thanked 0 Times in 0 Posts
umair434 is on a distinguished road
timestamp when a button is clicked

Hi,

So I have a form set up which has a button.. the onclick event of this button runs some code and produces a report.. This usually takes 2-3 mins.

I am actually looking for a way that if it has been less than 20 mins since the user clicked that button, a macro is skipped (no need since data wont be updated)..i.e a line of code is skipped.


something alone the line:

If datediff("mi", timestamp, now()) < 20 then..


^ something's wrong here .. any suggestions please?

umair434 is offline   Reply With Quote
Old 07-31-2012, 09:57 AM   #2
rctjoe24
Newly Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 0
Thanked 7 Times in 6 Posts
rctjoe24 is on a distinguished road
Re: timestamp when a button is clicked

I think you're looking for,

If datediff("n", timestamp, now()) < 20 then
From the Access Help File, these are the Time Intervals;
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
rctjoe24 is offline   Reply With Quote
Old 07-31-2012, 10:27 AM   #3
umair434
Newly Registered User
 
Join Date: Jul 2011
Location: CA
Posts: 186
Thanks: 24
Thanked 0 Times in 0 Posts
umair434 is on a distinguished road
Re: timestamp when a button is clicked

but how do I find the time when the button is clicked?

umair434 is offline   Reply With Quote
Old 07-31-2012, 11:32 AM   #4
rctjoe24
Newly Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 0
Thanked 7 Times in 6 Posts
rctjoe24 is on a distinguished road
Re: timestamp when a button is clicked

Easiest solution would be to declare a form level variable at the top of the form just after the Option Compare Database with something like;

Public mdtmTimeStamp as date

When you click the button that launches the report, prior to actually launching the report add the following code;

mdtmTimeStamp = now()

When the report finishes running, you can do a time difference like this

If DateDiff("n",mdtmTimeStamp,now()) > 20 then
.....
End IF

I chose to make the variable public in the form module because it is only set by this form and is only referenced by the one report. In some other cases it may be wiser to move the variable to a module which can be accessed by all Access object.
rctjoe24 is offline   Reply With Quote
Old 07-31-2012, 11:47 AM   #5
umair434
Newly Registered User
 
Join Date: Jul 2011
Location: CA
Posts: 186
Thanks: 24
Thanked 0 Times in 0 Posts
umair434 is on a distinguished road
Re: timestamp when a button is clicked

Quote:
Originally Posted by rctjoe24 View Post
Easiest solution would be to declare a form level variable at the top of the form just after the Option Compare Database with something like;

Public mdtmTimeStamp as date

When you click the button that launches the report, prior to actually launching the report add the following code;

mdtmTimeStamp = now()

When the report finishes running, you can do a time difference like this

If DateDiff("n",mdtmTimeStamp,now()) > 20 then
.....
End IF

I chose to make the variable public in the form module because it is only set by this form and is only referenced by the one report. In some other cases it may be wiser to move the variable to a module which can be accessed by all Access object.

that's what I tried before but timestamp always equals now().. the difference always turns out to be 0. Somehow I need to find the time when the button is clicked..Now() just shows the true time.
umair434 is offline   Reply With Quote
Old 07-31-2012, 12:55 PM   #6
rctjoe24
Newly Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 0
Thanked 7 Times in 6 Posts
rctjoe24 is on a distinguished road
Re: timestamp when a button is clicked

Quote:
Originally Posted by umair434 View Post
that's what I tried before but timestamp always equals now().. the difference always turns out to be 0. Somehow I need to find the time when the button is clicked..Now() just shows the true time.
Maybe I'm not explaining this well enough and for that I'm sorry.

I'm starting to think that the form which contains the button to open the report is closed after you click it. For that reason the variable would be set to nothing. In addition if you don't explicitly dimension your variables with "Option Explicit" at the top of each module, it would assume the variable as a date and default it to current date?

Anyway, the best course of action is to add the variable I was speaking of, mdtmTimeStamp, to a module. When the report is finished running, DateDiff function will be looking at a date different than the current date/time.

rctjoe24 is offline   Reply With Quote
Old 07-31-2012, 12:57 PM   #7
rctjoe24
Newly Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 0
Thanked 7 Times in 6 Posts
rctjoe24 is on a distinguished road
Re: timestamp when a button is clicked

Quote:
Originally Posted by umair434 View Post
that's what I tried before but timestamp always equals now().. the difference always turns out to be 0. Somehow I need to find the time when the button is clicked..Now() just shows the true time.

Also make sure you put the mdtmTimeStamp = now()
BEFORE you run docmd.openreport

It must be in this order or else you would get a 0 when you run the datediff.

rctjoe24 is offline   Reply With Quote
Old 08-01-2012, 04:35 AM   #8
umair434
Newly Registered User
 
Join Date: Jul 2011
Location: CA
Posts: 186
Thanks: 24
Thanked 0 Times in 0 Posts
umair434 is on a distinguished road
Re: timestamp when a button is clicked

Tried everything.. it still gives 0. I'm missing something here
umair434 is offline   Reply With Quote
Old 08-02-2012, 11:44 AM   #9
rctjoe24
Newly Registered User
 
Join Date: Jul 2012
Posts: 28
Thanks: 0
Thanked 7 Times in 6 Posts
rctjoe24 is on a distinguished road
Re: timestamp when a button is clicked

could you paste your code in this window so I could have a look?

rctjoe24 is offline   Reply With Quote
Reply

Tags
button , form , timestamp , user activity

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
activate button after another button clicked honnour Forms 7 07-07-2012 05:16 AM
disable button until button above is clicked newtoaccess Forms 2 07-16-2009 11:15 AM
Update a timestamp when a button is pressed JBHTeng05 General 3 05-29-2008 10:54 AM
Question about Radio button and Timestamp fastmike Forms 2 09-20-2007 08:00 AM
Button and timestamp kermit95 Forms 2 04-17-2001 09:50 PM




All times are GMT -8. The time now is 02:53 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World