Access World Forums

Access World Forums (https://www.access-programmers.co.uk/forums/index.php)
-   Forms (https://www.access-programmers.co.uk/forums/forumdisplay.php?f=9)
-   -   timestamp when a button is clicked (https://www.access-programmers.co.uk/forums/showthread.php?t=230888)

umair434 07-31-2012 09:54 AM

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?:confused:

rctjoe24 07-31-2012 09:57 AM

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

umair434 07-31-2012 10:27 AM

Re: timestamp when a button is clicked
 
but how do I find the time when the button is clicked?

rctjoe24 07-31-2012 11:32 AM

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.

umair434 07-31-2012 11:47 AM

Re: timestamp when a button is clicked
 
Quote:

Originally Posted by rctjoe24 (Post 1177955)
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.

rctjoe24 07-31-2012 12:55 PM

Re: timestamp when a button is clicked
 
Quote:

Originally Posted by umair434 (Post 1177962)
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? :confused:

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 07-31-2012 12:57 PM

Re: timestamp when a button is clicked
 
Quote:

Originally Posted by umair434 (Post 1177962)
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.

umair434 08-01-2012 04:35 AM

Re: timestamp when a button is clicked
 
Tried everything.. it still gives 0. I'm missing something here :(

rctjoe24 08-02-2012 11:44 AM

Re: timestamp when a button is clicked
 
could you paste your code in this window so I could have a look?


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

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