Check on Dates.

  • Thread starter Thread starter jfaz
  • Start date Start date
J

jfaz

Help I am new to this and although have basic idea do not understand coding
enought to do what I need.
I have 2 tables - project details and property details
One form has been created from a query based on the two tables above.
On project details I have a start date field. On property details I also
have a start date field. (there can be many properties on one project).

I want to ensure that a user does not input a date in the property details
start date field which is before the project start date.

I would be grateful if someone could point me in the direction so I can
achieve this.

Many thank for any help in advance.
 
Something along these lines should get you there:

Private Sub Property_START_DATE_BeforeUpdate(Cancel As Integer)
If Nz(Project_START_DATE) <> "" And Nz(Property_START_DATE) <> "" Then
If Property_START_DATE < Project_START_DATE Then
MsgBox "The Property cannot start before the Project", vbCritical,
"Data Error"
Cancel = True
End If
End If
End Sub

Substituting your own field names of course!

HTH
John
##################################
Don't Print - Save trees
 
In the BeforeUpdate event of the Property Start Date field, put some code
similar to:

Private Sub txt_PropertyStartDate_BeforeUpdate(Cancel as integer)

if LEN(me.txt_PropertyStartDate & "") = 0 then
msgbox "Enter a property start date!"
Cancel = true
elseif Cdate(me.txt_PropertyStartDate) < cdate(me.txt_ProjectStartDate)
Then
msgbox "Property start date cannot preceed project start date!"
cancel = true
End if

End Sub

This will test to see whether the property start date is empty or if it is
before the project start date, and will cancel the update if it fails either
test.

HTH
Dale
 
Back
Top