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 / October 2005

Tip: Looking for answers? Try searching our database.

Date and Time Condition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bladelock - 24 Oct 2005 14:57 GMT
Hi all,

I have a small problem with user enter the wrong date or time. Here is my
problem on an input form: The user sometimes enters the wrong time or date
Example
(Text Boxes on the form)
Date1             Time1        Date2         Time2
01/01/2005     23:00    01/01/2005      23:44    This is correct
01/02/2005     19:25    01/01/2005      21:55    This is correct
01/01/2005     20:22    01/01/2005      20:11    This is WRONG

The date should be 01/02/2005!! How can I control this so the user can't
enter the wrong date or time. I need some type of code for Date2 and Time2.
How can I code this? Thanks
'69 Camaro - 24 Oct 2005 16:55 GMT
Since one can't tell the user that "Date2 is wrong!" you should find
something more descriptive.  Here's an example where the check in date and
time must be later than the checkout date and time.  BTW, one can use a
Date/Time field to store both the date and the time, but if they need to be
separated for display purposes, then the DateValue( ) and TimeValue( )
functions can be used.

Private Sub ChkInDate_BeforeUpdate(Cancel As Integer)

   On Error GoTo ErrHandler
   
   If (Me!ChkInDate.Value < Me!ChkOutDate.Value) Then
       MsgBox "You cannot check in the item" & vbCrLf & _
           "before you check it out!", vbCritical + vbOKOnly, "Invalid Date!"
       Cancel = True
   End If
   
   Exit Sub
   
ErrHandler:
   
   MsgBox "Error in ChkInDate_BeforeUpdate( ) in" & vbCrLf & _
       Me.Name & " form." & vbCrLf & vbCrLf & _
       "Error #" & Err.Number & vbCrLf & Err.Description
   Err.Clear

End Sub

Private Sub ChkInTime_BeforeUpdate(Cancel As Integer)

   On Error GoTo ErrHandler
   
   If (Me!ChkInTime.Value < Me!ChkOutTime.Value) Then
       If (Me!ChkInDate.Value <= Me!ChkOutDate.Value) Then
           MsgBox "You cannot check in the item" & vbCrLf & _
               "before you check it out!", vbCritical + vbOKOnly, _
               "Invalid Date And Time!"
           Cancel = True
       End If
   End If
   
   Exit Sub
   
ErrHandler:
   
   MsgBox "Error in ChkInTime_BeforeUpdate( ) in" & vbCrLf & _
       Me.Name & " form." & vbCrLf & vbCrLf & _
       "Error #" & Err.Number & vbCrLf & Err.Description
   Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers.  Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.

> Hi all,
>
[quoted text clipped - 10 lines]
> enter the wrong date or time. I need some type of code for Date2 and Time2.
> How can I code this? Thanks
bladelock - 25 Oct 2005 19:37 GMT
You're very smart, thank you.

> Since one can't tell the user that "Date2 is wrong!" you should find
> something more descriptive.  Here's an example where the check in date and
[quoted text clipped - 78 lines]
> > enter the wrong date or time. I need some type of code for Date2 and Time2.
> > How can I code this? Thanks
'69 Camaro - 25 Oct 2005 20:51 GMT
You're very welcome.  And thanks, but it's just a matter of "been there,
done that" a few times, so you'll find these solutions easy to come by after
you've worked with Access for a while.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

> You're very smart, thank you.
>
[quoted text clipped - 91 lines]
>> > Time2.
>> > How can I code this? Thanks
 
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.