How to Disable a button on a form (1 Viewer)

tvman5683

Registered User.
Local time
Today, 15:46
Joined
Oct 2, 2008
Messages
42
Hello,
Is there a way to disable a form button at a fixed time every day?
I want to prevent multiple users from creating activity past 3:00 PM each day.

Thanks
JB
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 21:46
Joined
Nov 30, 2015
Messages
106
Create a timer on the form. Then in OnTimer event:
Code:
If Hour(Now) > 14 Then
        YourButton.Enabled = False
    End If
Your Timer can have interval of 1 minute unless you want to be more precise then set it to 5 seconds or even 1. Up to you.
 

tvman5683

Registered User.
Local time
Today, 15:46
Joined
Oct 2, 2008
Messages
42
Thanks, I will give it a try today and let you know if it worked out.
 

tvman5683

Registered User.
Local time
Today, 15:46
Joined
Oct 2, 2008
Messages
42
Tried adding the code to the On Timer property but had no affect on the button.


Private Sub Form_Timer()
If Hour(Now) > 10 Then
[Append to Daily].Enabled = False
End If
End Sub
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 21:46
Joined
Nov 30, 2015
Messages
106
You need to set timer interval as well. In properties window for the form, on the Event tab - Timer Interval, it's in miliseconds so 1000 means 1s.
Also I'd avoid spaces and special characters in object/control names, that's asking for trouble. Maybe change name of the button to: btAppendToDaily? And reference to it Me.btAppendToDaily.Enabled.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:46
Joined
Feb 28, 2001
Messages
27,192
If it is a bound form, put your test in the Form_Current routine. You can also do this a different way... put it in the {control}_Click routine to test the time and pop up a message box when outside of the approved hours. By the way, you might want to do that test just a little different. Let's say your approved update hours are 0700 to 1500 (military, of course).

Do the test where Hour(Now) >= 7 and Hour(Now) < 15. If you fail the test (i.e. outside the hours in question), do a message box but don't necessarily disable the button. Just make the code jump to the control_Click_Exit label that is normally built by the wizard.
 

tvman5683

Registered User.
Local time
Today, 15:46
Joined
Oct 2, 2008
Messages
42
This did work and set the interval to 10000. Probably will increase to 60000 for a 10 minute check period.
Thanks for the help!

JB




Private Sub Form_Timer()
If Time >= TimeValue("10:35") Then
Append_to_Daily.Enabled = False
End If
End Sub
 

tvman5683

Registered User.
Local time
Today, 15:46
Joined
Oct 2, 2008
Messages
42
Thanks for the suggestion Doc_Man. I'm going to try it also to see which is better. I like the idea of the message but I am afraid if the button is not disabled some will still try to use the function. (which creates a problem in the external process we have that captures the data we are exporting with the button)
 

Users who are viewing this thread

Top Bottom