ensuring that date1 is not null before Date 2

GetReel

Registered User.
Local time
Today, 20:39
Joined
May 22, 2003
Messages
67
I had a quick search but couldnt find what I was looking for ,

I have a date field called txtDateReceived and another date called txtDateAllocated. I have these date inorder to calculate the no of cases have been allocate greater than 3 days. I have notice that some staff are failed to record the Date received.

What I would like is for the form to check to see if txtDateReceived is not null before txtDAteAllocated can be entered or if any other field is started to be filled in. The below code work Ok but only works when the record is attempted to be save.



Ive come up with this after a little search. I thought I would share it in case others would like to used it. Place it on before update event on the form.

If IsNull(Me.[txtDateAllegReceived]) Then
Me.[txtDateAllegReceived].SetFocus
MsgBox "You must enter the IMU Allegation received Date", , "Missing Data"
Cancel = True
Exit Sub
End If
'make sure the second Date is filled out
If IsNull(Me.[txtDateAllocated]) Then
Me.[txtDateAllocated].SetFocus
MsgBox "You must enter the Date Allocated to Investigations", , "Missing Data"
Cancel = True
Exit Sub
End If
'make sure the second Date is >= Date 1
If Me.[txtDateAllocated] < Me.[txtDateAllegReceived] Then
Me.[txtDateAllocated].SetFocus
MsgBox "The Date Allocated must greater or equal to Date received >= " & Me.[txtDateAllegReceived], , "Invalid Data"
Cancel = True
Exit Sub
End If
End Sub
 
Last edited:
As my signature suggests, there's almost always multiple ways to solve a given question, but the first question can be solved with:
Code:
Private Sub txtDateAllocated_Enter()
If IsNull(Me.txtDateReceived) Then
  MsgBox "You cannot proceed until you have added the date received"
  Me.txtDateReceived.SetFocus
End If
End Sub
And the second question like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Field1) Then
 MsgBox "You must fill in Field1!"
 Cancel = True
 Me.Field1.SetFocus
End If
If IsNull(Me.Field2) Then
 MsgBox "You must fill in Field2!"
 Cancel = True 
 Me.Field2.SetFocus
End If
If IsNull(Me.Field3) Then
 MsgBox "You must fill in Field3!"
 Cancel = True 
 Me.Field3.SetFocus
End If
End Sub
 
Thanks ..I try to employ it.
 

Users who are viewing this thread

Back
Top Bottom