Enable/disable cmd button after some period of time

seito

New member
Local time
Today, 23:16
Joined
Apr 20, 2012
Messages
3
Hy vba saviors :)!

I'm very rusty with this and any help would be much appreciated...

So this is my setup. I have database for my users. And I wish to give them an option to take a break ONLY after certain period of time.

What I did:
I created a button and choose Enabled NO. Not much, I know :)!

What I wish this button would do:
Idea is that 60 min after initial log-in (log-in times are stored in table) some VBA code would switch this button's Enabled property to YES. So that user can now click on it and take much needed relaxation time.

So, what I need and where I'm lost?
I need code that looks in table where log-in times are stored (let's call it "tbl_login"), search for LAST log-in time for this specific user (current user can be looked up as Temporary Variable, lets call it "tempUser" ) then compare it with current time (I guess function time would be ok) and if difference is more than 60 min it changes Enabled property of button from NO to YES.

Any guidance, idea or even a solution for this would be MUCH appreciated!

Thank you in advance!
 
You can use the On_Timer property of the form. Use the interval as much as you want maybe 300000 (5 minutes). And inside the On_Timer property code use a simple If condition to check,

Code:
If(DLookUp("last_login","tbl_login","user=username")+ TimeValue("00:59")>=Now()) Then
button.enable=true
End if
 
Hy. Thank you for input. Sadly, I already have set On_Timer end interval for another event. And as it is interval must be very short, for now only 1s (1000ms).

So, this could work if it's possible to set another On_Timer event that would fire only after, lets say, 3600 intervals. Is this possible?
 
You can use the On_Timer property of the form. Use the interval as much as you want maybe 300000 (5 minutes). And inside the On_Timer property code use a simple If condition to check,

Code:
If(DLookUp("last_login","tbl_login","user=username")+ TimeValue("00:59")>=Now()) Then
button.enable=true
End if

OK, never mind my previous post. That was stupid from me :)! I now see what you meant with On_Timer property.

I tried with your code and we are on the right track. I only needs some polishing... I think.

At the moment it's like:
Code:
If (DLookup("table_field_login_times", "tbl_login", "ID_user =" TempVars("TempCurentUser").Value) + TimeValue("00:01") >= Now()) Then
button.Enabled = True

And I get an error in comparing loged in user ID, which is stored as tempvar to field ID-user in table tbl_login.

Any idea what I'm doing wrong?
 
I believe the syntax might be wrong.. Make sure that you are not comparing a string to a number field and also use the ampersand symbol to access any variable. As in

DLookUp("column_name","table_name","user_id="& variable_name &" ")

in case if the user_id is a string enclose it within single quotes. As in

DLookUp("column_name","table_name","user_id=' "& variable_name &" ' ")
 

Users who are viewing this thread

Back
Top Bottom