By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,390 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

time

P: 58
Hello,

Is there a way I can see if the current time is between two set times when someone presses a button? what i have is a DB that people log onto at the beginning and log off at the end of the shift. What I want is to have it set up that if they press the log out button before a certain time, it will not let them log out. for night shift it will be 5:30 AM and for dayshift it will be 5:30pm. I hope this makes sense.


Andrew
Dec 21 '07 #1
Share this Question
Share on Google+
3 Replies


P: 68
Hello,

Is there a way I can see if the current time is between two set times when someone presses a button? what i have is a DB that people log onto at the beginning and log off at the end of the shift. What I want is to have it set up that if they press the log out button before a certain time, it will not let them log out. for night shift it will be 5:30 AM and for dayshift it will be 5:30pm. I hope this makes sense.


Andrew
I assume you have an exit command button that users click to exit the db. On the On_Click event, do something like this;

Expand|Select|Wrap|Line Numbers
  1. Dim MyTime
  2. MyTime = #5:30:00 AM#
  3. If Now() < MyTime
  4. MsgBox "You're a bit too early", vbInformation + vbOKOnly + vbDefaultButton1, "Log Off"
  5. exit sub
  6. Else
  7. 'your logout routine
  8. End If
If you haven't already done so you may want to hide the Access Close button to prevent users bypassing your logout routine, you'll find this on
http://www.thescripts.com/forum/thread206622.html

HTH
Kevin
Dec 21 '07 #2

P: 58
Thanks,
The majority of it worked, but i had to change Now() to Time. Once I did that it worked.
Thanks for steering me in the right direction, i greatly appreciate it

Andrew
Dec 21 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
Nice work Kevin :)
As you mention the close button though, I'll share the method I use to ensure that it doesn't bypass your code, while allowing the operator to use the familiar close button if they wish.
Basically, you handle the close (Form_Close()) as you would want to, then simply call code to close the form from within the routine that handles your Exit button (or whatever you use for your controlled exit).
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExit_Click()
  2.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Name)
  3. End Sub
  4.  
  5. Private Sub Form_Close()
  6.     'Your closing code here
  7. End Sub
Dec 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.