Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / December 2007

Tip: Looking for answers? Try searching our database.

How to show an error when time out is less than time in.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joy - 30 Nov 2007 21:37 GMT
I have a form in which we enter the time in (set as Medium Time) and time out
(set as Medium Time) and then another box I have a formula (=[Time Out]-[Time
In]) which shows the time spent.  Is there a way to have an error window pop
up if the time out is before the time in? Or someway to stop an entry being
made?  
Signature

Thanks, Joy

Ken Snell (MVP) - 30 Nov 2007 23:19 GMT
Use the form's BeforeUpdate event to test the conditions:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[Time Out].Value & "") = 0 Then
   MsgBox "You must enter a value for the Time Out data!"
   Cancel = True
ElseIf Len(Me.[Time In].Value & "") = 0 Then
   MsgBox "You must enter a value for the Time In data!"
   Cancel = True
ElseIf DateDiff("s", Me.[Time Out].Value, Me.[Time In].Value) > 0 Then
   MsgBox "Time Out value is earlier than Time In value!"
   Cancel = True
End If
End Sub

Signature

       Ken Snell
<MS ACCESS MVP>

>I have a form in which we enter the time in (set as Medium Time) and time
>out
[quoted text clipped - 5 lines]
> being
> made?
John W. Vinson - 30 Nov 2007 23:59 GMT
>I have a form in which we enter the time in (set as Medium Time) and time out
>(set as Medium Time) and then another box I have a formula (=[Time Out]-[Time
>In]) which shows the time spent.  Is there a way to have an error window pop
>up if the time out is before the time in? Or someway to stop an entry being
>made?  

Does your field contain just a time, or a date and time? Will you ever have
the situation where the TimeIn is 11:50pm and the TimeOut 2:30am? If so you
may want to consider using both the date and time, not just the time.

That said... in your Form's BeforeUpdate event you can click the ... icon,
choose Code Builder, and edit the code to:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If [Time In] > [Time Out] Then
   MsgBox "You can't finish before you start!!!"
   Cancel = True
   Me![Time Out].SetFocus
End If
End Sub

            John W. Vinson [MVP]
Joy - 10 Dec 2007 19:57 GMT
I must be doing something wrong because I can't get either of these to work.  
I only use time.  Date is not an issue.  Can you offer some more advice?
Signature

Thanks, Joy

> >I have a form in which we enter the time in (set as Medium Time) and time out
> >(set as Medium Time) and then another box I have a formula (=[Time Out]-[Time
[quoted text clipped - 18 lines]
>
>              John W. Vinson [MVP]
Ken Snell (MVP) - 11 Dec 2007 03:31 GMT
Tell us how you set up the approaches/code, and what happens when you "run"
the code. Also, show us some examples of data that, when entered, should
produce the error that you want to bring to the user's attention.
Signature


       Ken Snell
<MS ACCESS MVP>

>I must be doing something wrong because I can't get either of these to
>work.
[quoted text clipped - 29 lines]
>>
>>              John W. Vinson [MVP]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.