Restrict editing of activity based on date comparison

Hi (again!) thanks to the help of many forum members i have built a system for our users.  I have a facility that allows users to do an end of month submission and it writes the date selected into a field called 'datelastsubmitted' in 'tblusers'.  the reason i am doing this is that i do not want users to then be able to go in and edit any activity that they have entered prior to that 'datelastsubmitted' value.  When they open up an activity to edit (as opposed to creating a new one) i want to be able to restrict them from editing the activity if the 'datelastsubmitted' value is more recent than the 'activitydate' value.  this form is based on a query between linked tables so datelastsubmitted and activitydate are able to be compared

However i dont know how to get this to compare the 2 dates and then allow or disallow editing (which is done by pressing the 'activityedit' command button).

 

An example is below

(This sets the form to be non-editable by default)

Private Sub Form_Load()
Me.AllowEdits = False

End Sub

Ive then been trying to tell this button to disallow editing if the 'datelastsubmitted' value is greater than the 'activitydate' value but i guess it doesnt work this way. 

Private Sub activityedit_Click()
Dim datelastsubmitted As Date
Dim activitydate As Date
If "#Me!datelastsubmitted.value# Is >= #Me!activitydate.value#" Then _
Me.AllowEdits = False
ElseIf "#Me!datelastsubmitted.value# Is <= #Me!activitydate.value#" Then
Me.AllowEdits = True
End If
End Sub

It also tells me that there is a type mismatch on the lines "If blah blah blah blah Then"

Can anyone tell me how it should be done

Thanks again,

Rhys.



Answer this question

Restrict editing of activity based on date comparison

  • Kamen

    cheers deerk - went away to sit down in a dark room and came back and got it working - cheers for the pointer.

    Rhys.


  • s o

    Hi Rhys,

    Glad your getting there, have a look at the DateDiff method. What you can do is find the difference between the dates and if the difference is less than zero then it will mean one thing and if the difference is greater than zero then it will mean another, and if zero then they are the same. I'm being a bit generic as you can check the number of days, the number of hours, and so on and it really depends what your looking for.

    Have a read of the help file as it's a powerful function, you'll find what your needing there.

    Also, you can use the CDate function to convert a string containing a date to a date variable, if you needing it.



  • rmtuckerphx

    nice one Rhys no worries, hope you left a window open.

  • Restrict editing of activity based on date comparison