Procedure to check date/time

  • Thread starter jesseu via AccessMonster.com
  • Start date
J

jesseu via AccessMonster.com

Hi all, New to code
I have a form with date txtbox operator needs to place both date and time of
job completion.
some just place dates and some place just the time. Need to write code on
before-update.
1. to check that both date and time is place
2. give message if either one is missing
3. not allowing next entry until both are given.

Thank You Team
Jesse
 
T

tina

if there is only one field to hold both the date and time, have you
considered using an input mask to control the data entry? something along
the lines of

99/99/00\ 99:00\ >LL;0;_

suggest you read up on the Input Mask property so you'll understand how it
works.

hth
 
J

John W. Vinson

Hi all, New to code
I have a form with date txtbox operator needs to place both date and time of
job completion.
some just place dates and some place just the time. Need to write code on
before-update.
1. to check that both date and time is place
2. give message if either one is missing
3. not allowing next entry until both are given.

Thank You Team
Jesse

The user can be trained to type Ctrl-; to automatically enter the current
system date and time; or you can put code in the textbox's doubleclick event:

Private Sub txtTimeComplete_DblClick()
Me!txtTimeComplete = Now
End Sub

to do the same.

If the user will be entering data at some time after the job completion, you
could use this code in the control's BeforeUpdate:

Private Sub txtTimeComplete_BeforeUpdate(Cancel as Integer)
If Not IsDate(Me!txtTimeComplete) Then
Cancel = True
MsgBox "Please enter the date and time of job completion", vbOKOnly
Elseif TimeValue(Me!txtTimeComplete) = 0 Then
Cancel = True
Msgbox "Please enter the time as well as the date", vbOKOnly
Elseif DateValue(Me!txtTimeComplete) = 0 Then
Cancel = True
Msgbox "Please enter the date as well as the time", vbOKOnly
End If
End Sub

Note that this will prevent the user from entering a completion if they
actually completed the job exactly at midnight, since that's the 0 of time.
 
Top